Transaction Format
This file is meant to be the single source of truth for how we serialize transactions in the Avalanche Virtual Machine (AVM). This document uses the primitive serialization format for packing and secp256k1 for cryptographic user identification.
Codec ID
Some data is prepended with a codec ID (unt16) that denotes how the data should
be deserialized. Right now, the only valid codec ID is 0 (0x00 0x00).
Transferable Output
Transferable outputs wrap an output with an asset ID.
What Transferable Output Contains
A transferable output contains an AssetID and an Output.
AssetIDis a 32-byte array that defines which asset this output references.Outputis an output, as defined below. Outputs have four possible types:SECP256K1TransferOutput,SECP256K1MintOutput,NFTTransferOutputandNFTMintOutput.
Gantt Transferable Output Specification
Proto Transferable Output Specification
Transferable Output Example
Let's make a transferable output:
AssetID:0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fOutput:"Example SECP256K1 Transfer Output from below"
Transferable Input
Transferable inputs describe a specific UTXO with a provided transfer input.
What Transferable Input Contains
A transferable input contains a TxID, UTXOIndex AssetID and an Input.
TxIDis a 32-byte array that defines which transaction this input is consuming an output from. Transaction IDs are calculated by taking sha256 of the bytes of the signed transaction.UTXOIndexis an int that defines which UTXO this input is consuming in the specified transaction.AssetIDis a 32-byte array that defines which asset this input references.Inputis an input, as defined below. This can currently only be a SECP256K1 transfer input
Gantt Transferable Input Specification
Proto Transferable Input Specification
Transferable Input Example
Let's make a transferable input:
TxID:0xf1e1d1c1b1a191817161514131211101f0e0d0c0b0a090807060504030201000UTXOIndex:5AssetID:0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fInput:"Example SECP256K1 Transfer Input from below"
Transferable Op
Transferable operations describe a set of UTXOs with a provided transfer operation. Only one Asset ID is able to be referenced per operation.
What Transferable Op Contains
A transferable operation contains an AssetID, UTXOIDs, and a TransferOp.
AssetIDis a 32-byte array that defines which asset this operation changes.UTXOIDsis an array of TxID-OutputIndex tuples. This array must be sorted in lexicographical order.TransferOpis a transferable operation object.
Gantt Transferable Op Specification
Proto Transferable Op Specification
Transferable Op Example
Let's make a transferable operation:
AssetID:0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fUTXOIDs:UTXOID:TxID:0xf1e1d1c1b1a191817161514131211101f0e0d0c0b0a090807060504030201000UTXOIndex:5
Op:"Example Transfer Op from below"
Outputs
Outputs have four possible types:
SECP256K1TransferOutput,
SECP256K1MintOutput,
NFTTransferOutput and
NFTMintOutput.
SECP256K1 Mint Output
A secp256k1 mint output is an output that is owned by a collection of addresses.
What SECP256K1 Mint Output Contains
A secp256k1 Mint output contains a TypeID, Locktime, Threshold, and Addresses.
TypeIDis the ID for this output type. It is0x00000006.Locktimeis a long that contains the Unix timestamp that this output can be spent after. The Unix timestamp is specific to the second.Thresholdis an int that names the number of unique signatures required to spend the output. Must be less than or equal to the length ofAddresses. IfAddressesis empty, must be 0.Addressesis a list of unique addresses that correspond to the private keys that can be used to spend this output. Addresses must be sorted lexicographically.
Gantt SECP256K1 Mint Output Specification
Proto SECP256K1 Mint Output Specification
SECP256K1 Mint Output Example
Let's make a SECP256K1 mint output with:
TypeID:6Locktime:54321Threshold:1Addresses:0x51025c61fbcfc078f69334f834be6dd26d55a9550xc3344128e060128ede3523a24a461c8943ab0859
SECP256K1 Transfer Output
A secp256k1 transfer output allows for sending a quantity of an asset to a collection of addresses after a specified Unix time.
What SECP256K1 Transfer Output Contains
A secp256k1 transfer output contains a TypeID, Amount, Locktime, Threshold, and Addresses.
TypeIDis the ID for this output type. It is0x00000007.Amountis a long that specifies the quantity of the asset that this output owns. Must be positive.Locktimeis a long that contains the Unix timestamp that this output can be spent after. The Unix timestamp is specific to the second.Thresholdis an int that names the number of unique signatures required to spend the output. Must be less than or equal to the length ofAddresses. IfAddressesis empty, must be 0.Addressesis a list of unique addresses that correspond to the private keys that can be used to spend this output. Addresses must be sorted lexicographically.
Gantt SECP256K1 Transfer Output Specification
Proto SECP256K1 Transfer Output Specification
SECP256K1 Transfer Output Example
Let's make a secp256k1 transfer output with:
TypeID:7Amount:12345Locktime:54321Threshold:1Addresses:0x51025c61fbcfc078f69334f834be6dd26d55a9550xc3344128e060128ede3523a24a461c8943ab0859
NFT Mint Output
An NFT mint output is an NFT that is owned by a collection of addresses.
What NFT Mint Output Contains
An NFT Mint output contains a TypeID, GroupID, Locktime, Threshold, and Addresses.
TypeIDis the ID for this output type. It is0x0000000a.GroupIDis an int that specifies the group this NFT is issued to.Locktimeis a long that contains the Unix timestamp that this output can be spent after. The Unix timestamp is specific to the second.Thresholdis an int that names the number of unique signatures required to spend the output. Must be less than or equal to the length ofAddresses. IfAddressesis empty, must be 0.Addressesis a list of unique addresses that correspond to the private keys that can be used to spend this output. Addresses must be sorted lexicographically.
Gantt NFT Mint Output Specification
Proto NFT Mint Output Specification
NFT Mint Output Example
Let's make an NFT mint output with:
TypeID:10GroupID:12345Locktime:54321Threshold:1Addresses:0x51025c61fbcfc078f69334f834be6dd26d55a9550xc3344128e060128ede3523a24a461c8943ab0859
NFT Transfer Output
An NFT transfer output is an NFT that is owned by a collection of addresses.
What NFT Transfer Output Contains
An NFT transfer output contains a TypeID, GroupID, Payload, Locktime, Threshold, and Addresses.
TypeIDis the ID for this output type. It is0x0000000b.GroupIDis an int that specifies the group this NFT was issued with.Payloadis an arbitrary string of bytes no long longer than 1024 bytes.Locktimeis a long that contains the Unix timestamp that this output can be spent after. The Unix timestamp is specific to the second.Thresholdis an int that names the number of unique signatures required to spend the output. Must be less than or equal to the length ofAddresses. IfAddressesis empty, must be 0.Addressesis a list of unique addresses that correspond to the private keys that can be used to spend this output. Addresses must be sorted lexicographically.
Gantt NFT Transfer Output Specification
Proto NFT Transfer Output Specification
NFT Transfer Output Example
Let's make an NFT transfer output with:
TypeID:11GroupID:12345Payload:NFT PayloadLocktime:54321Threshold:1Addresses:0x51025c61fbcfc078f69334f834be6dd26d55a9550xc3344128e060128ede3523a24a461c8943ab0859
Inputs
Inputs have one possible type: SECP256K1TransferInput.
SECP256K1 Transfer Input
A secp256k1 transfer input allows for spending an unspent secp256k1 transfer output.
What SECP256K1 Transfer Input Contains
A secp256k1 transfer input contains an Amount and AddressIndices.
TypeIDis the ID for this input type. It is0x00000005.Amountis a long that specifies the quantity that this input should be consuming from the UTXO. Must be positive. Must be equal to the amount specified in the UTXO.AddressIndicesis a list of unique ints that define the private keys that are being used to spend the UTXO. Each UTXO has an array of addresses that can spend the UTXO. Each int represents the index in this address array that will sign this transaction. The array must be sorted low to high.
Gantt SECP256K1 Transfer Input Specification
Proto SECP256K1 Transfer Input Specification
SECP256K1 Transfer Input Example
Let's make a payment input with:
TypeId:5Amount:123456789AddressIndices: [3,7]
Operations
Operations have three possible types: SECP256K1MintOperation, NFTMintOp, and NFTTransferOp.
SECP256K1 Mint Operation
A secp256k1 mint operation consumes a SECP256K1 mint output, creates a new mint output and sends a transfer output to a new set of owners.
What SECP256K1 Mint Operation Contains
A secp256k1 Mint operation contains a TypeID, AddressIndices, MintOutput, and TransferOutput.
TypeIDis the ID for this output type. It is0x00000008.AddressIndicesis a list of unique ints that define the private keys that are being used to spend the UTXO. Each UTXO has an array of addresses that can spend the UTXO. Each int represents the index in this address array that will sign this transaction. The array must be sorted low to high.MintOutputis a SECP256K1 Mint output.TransferOutputis a SECP256K1 Transfer output.
Gantt SECP256K1 Mint Operation Specification
Proto SECP256K1 Mint Operation Specification
SECP256K1 Mint Operation Example
Let's make a secp256k1 mint operation with:
TypeId:8AddressIndices:0x000000030x00000007MintOutput:"Example SECP256K1 Mint Output from above"TransferOutput:"Example SECP256K1 Transfer Output from above"
NFT Mint Op
An NFT mint operation consumes an NFT mint output and sends an unspent output to a new set of owners.
What NFT Mint Op Contains
An NFT mint operation contains a TypeID, AddressIndices, GroupID, Payload, and Output of addresses.
TypeIDis the ID for this operation type. It is0x0000000c.AddressIndicesis a list of unique ints that define the private keys that are being used to spend the UTXO. Each UTXO has an array of addresses that can spend the UTXO. Each int represents the index in this address array that will sign this transaction. The array must be sorted low to high.GroupIDis an int that specifies the group this NFT is issued to.Payloadis an arbitrary string of bytes no longer than 1024 bytes.Outputis not aTransferableOutput, but rather is a lock time, threshold, and an array of unique addresses that correspond to the private keys that can be used to spend this output. Addresses must be sorted lexicographically.
Gantt NFT Mint Op Specification
Proto NFT Mint Op Specification
NFT Mint Op Example
Let's make an NFT mint operation with:
TypeId:12AddressIndices:0x000000030x00000007
GroupID:12345Payload:0x431100Locktime:54321Threshold:1Addresses:0xc3344128e060128ede3523a24a461c8943ab0859
NFT Transfer Op
An NFT transfer operation sends an unspent NFT transfer output to a new set of owners.
What NFT Transfer Op Contains
An NFT transfer operation contains a TypeID, AddressIndices and an untyped NFTTransferOutput.
TypeIDis the ID for this output type. It is0x0000000d.AddressIndicesis a list of unique ints that define the private keys that are being used to spend the UTXO. Each UTXO has an array of addresses that can spend the UTXO. Each int represents the index in this address array that will sign this transaction. The array must be sorted low to high.NFTTransferOutputis the output of this operation and must be an NFT Transfer Output. This output doesn't have theTypeId, because the type is known by the context of being in this operation.
Gantt NFT Transfer Op Specification
Proto NFT Transfer Op Specification
NFT Transfer Op Example
Let's make an NFT transfer operation with:
TypeID:13AddressIndices:0x000000070x00000003GroupID:12345Payload:0x431100Locktime:54321Threshold:1Addresses:0xc3344128e060128ede3523a24a461c8943ab08590x51025c61fbcfc078f69334f834be6dd26d55a955
Initial State
Initial state describes the initial state of an asset when it is created. It contains the ID of the feature extension that the asset uses, and a variable length array of outputs that denote the genesis UTXO set of the asset.
What Initial State Contains
Initial state contains a FxID and an array of Output.
FxIDis an int that defines which feature extension this state is part of. For SECP256K1 assets, this is0x00000000. For NFT assets, this is0x00000001.Outputsis a variable length array of outputs, as defined above.
Gantt Initial State Specification
Proto Initial State Specification
Initial State Example
Let's make an initial state:
FxID:0x00000000InitialState:["Example SECP256K1 Transfer Output from above"]
Credentials
Credentials have two possible types: SECP256K1Credential, and NFTCredential.
Each credential is paired with an Input or Operation. The order of the
credentials match the order of the inputs or operations.
SECP256K1 Credential
A secp256k1 credential contains a list of 65-byte recoverable signatures.
What SECP256K1 Credential Contains
TypeIDis the ID for this type. It is0x00000009.Signaturesis an array of 65-byte recoverable signatures. The order of the signatures must match the input's signature indices.
Gantt SECP256K1 Credential Specification
Proto SECP256K1 Credential Specification
SECP256K1 Credential Example
Let's make a payment input with:
TypeID:9signatures:0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1e1d1f202122232425262728292a2b2c2e2d2f303132333435363738393a3b3c3d3e3f000x404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5e5d5f606162636465666768696a6b6c6e6d6f707172737475767778797a7b7c7d7e7f00
NFT Credential
An NFT credential is the same as an secp256k1 credential with a
different TypeID. The TypeID for an NFT credential is 0x0000000e.
Unsigned Transactions
Unsigned transactions contain the full content of a transaction with only the
signatures missing. Unsigned transactions have four possible types:
CreateAssetTx,
OperationTx,
ImportTx,
and
ExportTx.
They all embed
BaseTx, which
contains common fields and operations.
Unsigned BaseTx
What Base TX Contains
A base TX contains a TypeID, NetworkID, BlockchainID, Outputs, Inputs, and Memo.
TypeIDis the ID for this type. It is0x00000000.NetworkIDis an int that defines which network this transaction is meant to be issued to. This value is meant to support transaction routing and is not designed for replay attack prevention.BlockchainIDis a 32-byte array that defines which blockchain this transaction was issued to. This is used for replay attack prevention for transactions that could potentially be valid across network or blockchain.Outputsis an array of transferable output objects. Outputs must be sorted lexicographically by their serialized representation. The total quantity of the assets created in these outputs must be less than or equal to the total quantity of each asset consumed in the inputs minus the transaction fee.Inputsis an array of transferable input objects. Inputs must be sorted and unique. Inputs are sorted first lexicographically by theirTxIDand then by theUTXOIndexfrom low to high. If there are inputs that have the sameTxIDandUTXOIndex, then the transaction is invalid as this would result in a double spend.MemoMemo field contains arbitrary bytes, up to 256 bytes.
Gantt Base TX Specification
Proto Base TX Specification
Base TX Example
Let's make an base TX that uses the inputs and outputs from the previous examples:
TypeID:0NetworkID:4BlockchainID:0xffffffffeeeeeeeeddddddddcccccccbbbbbbbbaaaaaaaa9999999988888888Outputs:"Example Transferable Output as defined above"
Inputs:"Example Transferable Input as defined above"
Memo:0x00010203
Unsigned CreateAssetTx
What Unsigned Create Asset TX Contains
An unsigned create asset TX contains a BaseTx, Name, Symbol,
Denomination, and InitialStates. The TypeID is 0x00000001.
BaseTxNameis a human readable string that defines the name of the asset this transaction will create. The name is not guaranteed to be unique. The name must consist of only printable ASCII characters and must be no longer than 128 characters.Symbolis a human readable string that defines the symbol of the asset this transaction will create. The symbol is not guaranteed to be unique. The symbol must consist of only printable ASCII characters and must be no longer than 4 characters.Denominationis a byte that defines the divisibility of the asset this transaction will create. For example, the AVAX token is divisible into billionths. Therefore, the denomination of the AVAX token is 9. The denomination must be no more than 32.InitialStatesis a variable length array that defines the feature extensions this asset supports, and the initial state of those feature extensions.
Gantt Unsigned Create Asset TX Specification
Proto Unsigned Create Asset TX Specification
Unsigned Create Asset TX Example
Let's make an unsigned base TX that uses the inputs and outputs from the previous examples:
BaseTx:"Example BaseTx as defined above with ID set to 1"Name:Volatility IndexSymbol:VIXDenomination:2InitialStates:"Example Initial State as defined above"
Unsigned OperationTx
What Unsigned Operation TX Contains
An unsigned operation TX contains a BaseTx, and Ops. The TypeID for this type is 0x00000002.
BaseTxOpsis a variable-length array of Transferable Ops.
Gantt Unsigned Operation TX Specification
Proto Unsigned Operation TX Specification
Unsigned Operation TX Example
Let's make an unsigned operation TX that uses the inputs and outputs from the previous examples:
BaseTx:"Example BaseTx above" with TypeID set to 2Ops: ["Example Transferable Op as defined above"]
Unsigned ImportTx
What Unsigned Import TX Contains
An unsigned import TX contains a BaseTx, SourceChain and Ins. * The TypeIDfor this type is 0x00000003.
BaseTxSourceChainis a 32-byte source blockchain ID.Insis a variable length array of Transferable Inputs.
Gantt Unsigned Import TX Specification
Proto Unsigned Import TX Specification
Unsigned Import TX Example
Let's make an unsigned import TX that uses the inputs from the previous examples:
BaseTx:"Example BaseTx as defined above", but withTypeIDset to3SourceChain:0x0000000000000000000000000000000000000000000000000000000000000000Ins:"Example SECP256K1 Transfer Input as defined above"
Unsigned ExportTx
What Unsigned Export TX Contains
An unsigned export TX contains a BaseTx, DestinationChain, and Outs. The
TypeID for this type is 0x00000004.
DestinationChainis the 32 byte ID of the chain where the funds are being exported to.Outsis a variable length array of Transferable Outputs.
Gantt Unsigned Export TX Specification
Proto Unsigned Export TX Specification
Unsigned Export TX Example
Let's make an unsigned export TX that uses the outputs from the previous examples:
BaseTx:"Example BaseTx as defined above", but withTypeIDset to4DestinationChain:0x0000000000000000000000000000000000000000000000000000000000000000Outs:"Example SECP256K1 Transfer Output as defined above"
Signed Transaction
A signed transaction is an unsigned transaction with the addition of an array of credentials.
What Signed Transaction Contains
A signed transaction contains a CodecID, UnsignedTx, and Credentials.
CodecIDThe only current valid codec id is00 00.UnsignedTxis an unsigned transaction, as described above.Credentialsis an array of credentials. Each credential will be paired with the input in the same index at this credential.
Gantt Signed Transaction Specification
Proto Signed Transaction Specification
Signed Transaction Example
Let's make a signed transaction that uses the unsigned transaction and credentials from the previous examples.
CodecID:0UnsignedTx:0x0000000100000004ffffffffeeeeeeeeddddddddccccccccbbbbbbbbaaaaaaaa999999998888888800000001000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f000000070000000000003039000000000000d431000000010000000251025c61fbcfc078f69334f834be6dd26d55a955c3344128e060128ede3523a24a461c8943ab085900000001f1e1d1c1b1a191817161514131211101f0e0d0c0b0a09080706050403020100000000005000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f0000000500000000075bcd150000000200000007000000030000000400010203Credentials0x0000000900000002000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1e1d1f202122232425262728292a2b2c2e2d2f303132333435363738393a3b3c3d3e3f00404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5e5d5f606162636465666768696a6b6c6e6d6f707172737475767778797a7b7c7d7e7f00
UTXO
A UTXO is a standalone representation of a transaction output.
What UTXO Contains
A UTXO contains a CodecID, TxID, UTXOIndex, AssetID, and Output.
CodecIDThe only validCodecIDis00 00TxIDis a 32-byte transaction ID. Transaction IDs are calculated by taking sha256 of the bytes of the signed transaction.UTXOIndexis an int that specifies which output in the transaction specified byTxIDthat this UTXO was created by.AssetIDis a 32-byte array that defines which asset this UTXO references.Outputis the output object that created this UTXO. The serialization of Outputs was defined above. Valid output types are SECP Mint Output, SECP Transfer Output, NFT Mint Output, NFT Transfer Output.
Gantt UTXO Specification
Proto UTXO Specification
UTXO Examples
Let's make a UTXO with a SECP Mint Output:
CodecID:0TxID:0x47c92ed62d18e3cccda512f60a0d5b1e939b6ab73fb2d011e5e306e79bd0448fUTXOIndex:0=0x00000001AssetID:0x47c92ed62d18e3cccda512f60a0d5b1e939b6ab73fb2d011e5e306e79bd0448fOutput:0x00000006000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c6276aa2a
Let's make a UTXO with a SECP Transfer Output from the signed transaction created above:
CodecID:0TxID:0xf966750f438867c3c9828ddcdbe660e21ccdbb36a9276958f011ba472f75d4e7UTXOIndex:0=0x00000000AssetID:0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fOutput:"Example SECP256K1 Transferable Output as defined above"
Let's make a UTXO with an NFT Mint Output:
CodecID:0TxID:0x03c686efe8d80c519f356929f6da945f7ff90378f0044bb0e1a5d6c1ad06bae7UTXOIndex:0=0x00000001AssetID:0x03c686efe8d80c519f356929f6da945f7ff90378f0044bb0e1a5d6c1ad06bae7Output:0x0000000a00000000000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c6276aa2a
Let's make a UTXO with an NFT Transfer Output:
CodecID:0TxID:0xa68f794a7de7bdfc5db7ba5b73654304731dd586bbf4a6d7b05be6e49de2f936UTXOIndex:0=0x00000001AssetID:0x03c686efe8d80c519f356929f6da945f7ff90378f0044bb0e1a5d6c1ad06bae7Output:0x0000000b000000000000000b4e4654205061796c6f6164000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c6276aa2a
GenesisAsset
An asset to be issued in an instance of the AVM's Genesis
What GenesisAsset Contains
An instance of a GenesisAsset contains an Alias, NetworkID, BlockchainID,
Outputs, Inputs, Memo, Name, Symbol, Denomination, and
InitialStates.
Aliasis the alias for this asset.NetworkIDdefines which network this transaction is meant to be issued to. This value is meant to support transaction routing and is not designed for replay attack prevention.BlockchainIDis the ID (32-byte array) that defines which blockchain this transaction was issued to. This is used for replay attack prevention for transactions that could potentially be valid across network or blockchain.Outputsis an array of transferable output objects. Outputs must be sorted lexicographically by their serialized representation. The total quantity of the assets created in these outputs must be less than or equal to the total quantity of each asset consumed in the inputs minus the transaction fee.Inputsis an array of transferable input objects. Inputs must be sorted and unique. Inputs are sorted first lexicographically by theirTxIDand then by theUTXOIndexfrom low to high. If there are inputs that have the sameTxIDandUTXOIndex, then the transaction is invalid as this would result in a double spend.Memois a memo field that contains arbitrary bytes, up to 256 bytes.Nameis a human readable string that defines the name of the asset this transaction will create. The name is not guaranteed to be unique. The name must consist of only printable ASCII characters and must be no longer than 128 characters.Symbolis a human readable string that defines the symbol of the asset this transaction will create. The symbol is not guaranteed to be unique. The symbol must consist of only printable ASCII characters and must be no longer than 4 characters.Denominationis a byte that defines the divisibility of the asset this transaction will create. For example, the AVAX token is divisible into billionths. Therefore, the denomination of the AVAX token is 9. The denomination must be no more than 32.InitialStatesis a variable length array that defines the feature extensions this asset supports, and the initial state of those feature extensions.
Gantt GenesisAsset Specification
GenesisAsset Example
Let's make a GenesisAsset:
Alias:asset1NetworkID:12345BlockchainID:0x0000000000000000000000000000000000000000000000000000000000000000Outputs: []Inputs: []Memo:2Zc54v4ek37TEwu4LiV3j41PUMRd6acDDU3ZCVSxE7XName:asset1Symbol:MFCADenomination:1InitialStates:"Example Initial State as defined above"
Last updated on