Blocks and Transactions
You can use the BlockData and TransactionData data structures to index important information about the Fuel network for your dApp.
BlockData
pub struct BlockData {
pub height: u64,
pub id: Bytes32,
pub producer: Option<Bytes32>,
pub time: i64,
pub transactions: Vec<TransactionData>,
}
The BlockData struct is how blocks are represented in the Fuel indexer. It contains metadata such as the ID, height, and time, as well as a list of the transactions it contains (represented by TransactionData). It also contains the public key hash of the block producer, if present.
TransactionData
pub struct TransactionData {
pub transaction: Transaction,
pub status: TransactionStatus,
pub receipts: Vec<Receipt>,
pub id: TxId,
}
The TransactionData struct contains important information about a transaction in the Fuel network. The id field is the transaction hash, which is a 32-byte string. The receipts field contains a list of Receipts, which are generated by a Fuel node during the execution of a Sway smart contract; you can find more information in the Receipts section.
Transaction
pub enum Transaction {
Script(Script),
Create(Create),
Mint(Mint),
}
Transaction refers to the Fuel transaction entity and can be one of three distinct types: Script, Create, or Mint. Explaining the differences between each of the types is out of scope for the Fuel indexer; however, you can find information about the Transaction type in the Fuel specifications.
enum TransactionType : uint8 {
Script = 0,
Create = 1,
Mint = 2,
}
| name | type | description |
|---|---|---|
type | TransactionType | Transaction type. |
data | One of TransactionScript, TransactionCreate, or TransactionMint | Transaction data. |
Transaction is invalid if:
type > TransactionType.CreategasLimit > MAX_GAS_PER_TXblockheight() < maturityinputsCount > MAX_INPUTSoutputsCount > MAX_OUTPUTSwitnessesCount > MAX_WITNESSES- No inputs are of type
InputType.CoinorInputType.Message - More than one output is of type
OutputType.Changefor any asset ID in the input set - Any output is of type
OutputType.Changefor any asset ID not in the input set - More than one input of type
InputType.Coinfor any Coin ID in the input set - More than one input of type
InputType.Contractfor any Contract ID in the input set - More than one input of type
InputType.Messagefor any Message ID in the input set
When serializing a transaction, fields are serialized as follows (with inner structs serialized recursively):
uint8,uint16,uint32,uint64: big-endian right-aligned to 8 bytes.byte[32]: as-is.byte[]: as-is, with padding zeroes aligned to 8 bytes.
When deserializing a transaction, the reverse is done. If there are insufficient bytes or too many bytes, the transaction is invalid.
TransactionScript
enum ReceiptType : uint8 {
Call = 0,
Return = 1,
ReturnData = 2,
Panic = 3,
Revert = 4,
Log = 5,
LogData = 6,
Transfer = 7,
TransferOut = 8,
ScriptResult = 9,
MessageOut = 10,
}
| name | type | description |
|---|---|---|
gasPrice | uint64 | Gas price for transaction. |
gasLimit | uint64 | Gas limit for transaction. |
maturity | uint32 | Block until which tx cannot be included. |
scriptLength | uint16 | Script length, in instructions. |
scriptDataLength | uint16 | Length of script input data, in bytes. |
inputsCount | uint8 | Number of inputs. |
outputsCount | uint8 | Number of outputs. |
witnessesCount | uint8 | Number of witnesses. |
receiptsRoot | byte[32] | Merkle root of receipts. |
script | byte[] | Script to execute. |
scriptData | byte[] | Script input data (parameters). |
inputs | Input[] | List of inputs. |
outputs | Output[] | List of outputs. |
witnesses | Witness[] | List of witnesses. |
Given helper len() that returns the number of bytes of a field.
Transaction is invalid if:
- Any output is of type
OutputType.ContractCreated scriptLength > MAX_SCRIPT_LENGTHscriptDataLength > MAX_SCRIPT_DATA_LENGTHscriptLength * 4 != len(script)scriptDataLength != len(scriptData)
IMPORTANT:
When signing a transaction,
receiptsRootis set to zero.When verifying a predicate,
receiptsRootis initialized to zero.When executing a script,
receiptsRootis initialized to zero.
The receipts root receiptsRoot is the root of the binary Merkle tree of receipts. If there are no receipts, its value is set to the root of the empty tree, i.e. 0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.
TransactionCreate
| name | type | description |
|---|---|---|
gasPrice | uint64 | Gas price for transaction. |
gasLimit | uint64 | Gas limit for transaction. |
maturity | uint32 | Block until which tx cannot be included. |
bytecodeLength | uint16 | Contract bytecode length, in instructions. |
bytecodeWitnessIndex | uint8 | Witness index of contract bytecode to create. |
storageSlotsCount | uint16 | Number of storage slots to initialize. |
inputsCount | uint8 | Number of inputs. |
outputsCount | uint8 | Number of outputs. |
witnessesCount | uint8 | Number of witnesses. |
salt | byte[32] | Salt. |
storageSlots | (byte[32], byte[32]])[] | List of storage slots to initialize (key, value). |
inputs | Input[] | List of inputs. |
outputs | Output[] | List of outputs. |
witnesses | Witness[] | List of witnesses. |
Transaction is invalid if:
- Any input is of type
InputType.Contract - Any output is of type
OutputType.ContractorOutputType.Variable - More than one output is of type
OutputType.Changewithasset_idof zero - Any output is of type
OutputType.Changewith non-zeroasset_id - It does not have exactly one output of type
OutputType.ContractCreated bytecodeLength * 4 > CONTRACT_MAX_SIZEtx.data.witnesses[bytecodeWitnessIndex].dataLength != bytecodeLength * 4bytecodeWitnessIndex >= tx.witnessesCount- The keys of
storageSlotsare not in ascending lexicographic order - The computed contract ID (see below) is not equal to the
contractIDof the oneOutputType.ContractCreatedoutput storageSlotsCount > MAX_STORAGE_SLOTS- The Sparse Merkle tree root of
storageSlotsis not equal to thestateRootof the oneOutputType.ContractCreatedoutput
Creates a contract with contract ID as computed here.
TransactionMint
The transaction is created by the block producer and is not signed. Since it is not usable outside of block creation or execution, all fields must be fully set upon creation without any zeroing.
| name | type | description |
|---|---|---|
txPointer | TXPointer | The location of the Mint transaction in the block. |
outputsCount | uint8 | Number of outputs. |
outputs | Output[] | List of outputs. |
Transaction is invalid if:
- Any output is not of type
OutputType.Coin - Any two outputs have the same
asset_id txPointeris zero or doesn't match the block.
TransactionStatus
pub enum TransactionStatus {
Failure {
block_id: String,
time: DateTime<Utc>,
reason: String,
},
SqueezedOut {
reason: String,
},
Submitted {
submitted_at: DateTime<Utc>,
},
Success {
block_id: String,
time: DateTime<Utc>,
},
}
TransactionStatus refers to the status of a Transaction in the Fuel network.