Receipts
When a Sway contract is deployed and called on a Fuel node, receipts may be generated during its execution. You can think of these receipts as informative objects that are emitted when certain things happen, e.g. transfers, messages, etc. By building indices for receipts, you can create mappings to store this data, allowing your application to answer queries about the contract.
The Fuel indexer currently supports the following receipt types:
Below we'll discuss each of these receipts and how you can leverage them to get the most out of your dApp.
Log
#![allow(unused)] fn main() { use fuel_types::ContractId; pub struct Log { pub contract_id: ContractId, pub ra: u64, pub rb: u64, } }
- A
Logreceipt is generated when callinglog()on a non-reference types in a Sway contracts.- Specifically
bool,u8,u16,u32, andu64.
- Specifically
- The
rafield includes the value being logged whilerbmay include a non-zero value representing a unique ID for theloginstance. - Read more about
Login the Fuel protocol ABI spec
LogData
#![allow(unused)] fn main() { use fuel_types::ContractId; pub struct LogData { pub contract_id: ContractId, pub data: Vec<u8>, pub rb: u64, pub len: u64, pub ptr: u64, } }
- A
LogDatareceipt is generated when callinglog()in a Sway contract on a reference type; this includes all types except non-reference types. - The
datafield will include the logged value as a hexadecimal.- The
rbfield will contain a unique ID that can be used to look up the logged data type.
- The
- Read more about
LogDatain the Fuel protocol ABI spec
MessageOut
#![allow(unused)] fn main() { use fuel_types::{MessageId, Bytes32, Address}; pub struct MessageOut { pub message_id: MessageId, pub sender: Address, pub recipient: Address, pub amount: u64, pub nonce: Bytes32, pub len: u64, pub digest: Bytes32, pub data: Vec<u8>, } }
- A
MessageOutreceipt is generated as a result of thesend_message()Sway method in which a message is sent to a recipient address along with a certain amount of coins. - The
datafield currently supports only a vector of non-reference types rather than something like a struct. - Read more about
MessageOutin the Fuel protocol ABI spec
Transfer
#![allow(unused)] fn main() { use fuel_types::{ContractId, AssetId}; pub struct Transfer { pub contract_id: ContractId, pub to: ContractId, pub amount: u64, pub asset_id: AssetId, pub pc: u64, pub is: u64, } }
- A
Transferreceipt is generated when coins are transferred to a contract as part of a Sway contract. - The
asset_idfield contains the asset ID of the transferred coins, as the FuelVM has built-in support for working with multiple assets.- The
pcandisfields aren't currently used for anything, but are included for completeness.
- The
- Read more about
Transferin the Fuel protocol ABI spec
TransferOut
#![allow(unused)] fn main() { use fuel_types::{ContractId, AssetId, Address}; pub struct TransferOut { pub contract_id: ContractId, pub to: Address, pub amount: u64, pub asset_id: AssetId, pub pc: u64, pub is: u64, } }
- A
TransferOutreceipt is generated when coins are transferred to an address rather than a contract. - Every other field of the receipt works the same way as it does in the
Transferreceipt. - Read more about
TransferOutin the Fuel protocol ABI spec
ScriptResult
#![allow(unused)] fn main() { pub struct ScriptResult { pub result: u64, pub gas_used: u64, } }
- A
ScriptResultreceipt is generated when a contract call resolves; that is, it's generated as a result of theRET,RETD, andRVRTinstructions. - The
resultfield will contain a0for success, and a non-zero value otherwise. - Read more about
ScriptResultin the Fuel protocol ABI spec