Transaction Format
This page is meant to be the single source of truth for how we serialize atomic
transactions in Coreth
. 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
).
Inputs
Inputs to Coreth Atomic Transactions are either an EVMInput
from this chain or
a TransferableInput
(which contains a SECP256K1TransferInput
) from another
chain. The EVMInput
will be used in ExportTx
to spend funds from this chain,
while the TransferableInput
will be used to import atomic UTXOs from another
chain.
EVM Input
Input type that specifies an EVM account to deduct the funds from as part of an ExportTx
.
What EVM Input Contains
An EVM Input contains an address
, amount
, assetID
, and nonce
.
Address
is the EVM address from which to transfer funds.Amount
is the amount of the asset to be transferred (specified in nAVAX for AVAX and the smallest denomination for all other assets).AssetID
is the ID of the asset to transfer.Nonce
is the nonce of the EVM account exporting funds.
Gantt EVM Input Specification
Proto EVM Input Specification
EVM Input Example
Let's make an EVM Input:
Address: 0x8db97c7cece249c2b98bdc0226cc4c2a57bf52fc
Amount: 2000000
AssetID: 0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
Nonce: 0
Transferable Input
Transferable Input wraps a SECP256K1TransferInput
. 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
.
TxID
is a 32-byte array that defines which transaction this input is consuming an output from.UTXOIndex
is an int that defines which utxo this input is consuming in the specified transaction.AssetID
is a 32-byte array that defines which asset this input references.Input
is aSECP256K1TransferInput
, as defined below.
Gantt Transferable Input Specification
Proto Transferable Input Specification
Transferable Input Example
Let's make a transferable input:
TxID: 0x6613a40dcdd8d22ea4aa99a4c84349056317cf550b6685e045e459954f258e59
UTXOIndex: 1
AssetID: 0xdbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db
Input: "Example SECP256K1 Transfer Input from below"
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
.
TypeID
is the ID for this input type. It is0x00000005
.Amount
is 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.AddressIndices
is 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
: 500000000000AddressIndices
: [0]
Outputs
Outputs to Coreth Atomic Transactions are either an EVMOutput
to be added to
the balance of an address on this chain or a TransferableOutput
(which
contains a SECP256K1TransferOutput
) to be moved to another chain.
The EVM Output will be used in ImportTx
to add funds to this chain, while the
TransferableOutput
will be used to export atomic UTXOs to another chain.
EVM Output
Output type specifying a state change to be applied to an EVM account as part of an ImportTx
.
What EVM Output Contains
An EVM Output contains an address
, amount
, and assetID
.
Address
is the EVM address that will receive the funds.Amount
is the amount of the asset to be transferred (specified in nAVAX for AVAX and the smallest denomination for all other assets).AssetID
is the ID of the asset to transfer.
Gantt EVM Output Specification
Proto EVM Output Specification
EVM Output Example
Let's make an EVM Output:
Address: 0x0eb5ccb85c29009b6060decb353a38ea3b52cd20
Amount: 500000000000
AssetID: 0xdbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db
Transferable Output
Transferable outputs wrap a SECP256K1TransferOutput
with an asset ID.
What Transferable Output Contains
A transferable output contains an AssetID
and an Output
which is a SECP256K1TransferOutput
.
AssetID
is a 32-byte array that defines which asset this output references.Output
is aSECP256K1TransferOutput
as defined below.
Gantt Transferable Output Specification
Proto Transferable Output Specification
Transferable Output Example
Let's make a transferable output:
AssetID: 0xdbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db
Output: "Example SECP256K1 Transfer Output from below"
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
.
TypeID
is the ID for this output type. It is0x00000007
.Amount
is a long that specifies the quantity of the asset that this output owns. Must be positive.Locktime
is a long that contains the Unix timestamp that this output can be spent after. The Unix timestamp is specific to the second.Threshold
is an int that names the number of unique signatures required to spend the output. Must be less than or equal to the length ofAddresses
. IfAddresses
is empty, must be 0.Addresses
is 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
: 1000000Locktime
: 0Threshold
: 1Addresses
:- 0x66f90db6137a78f76b3693f7f2bc507956dae563
Atomic Transactions
Atomic Transactions are used to move funds between chains. There are two types ImportTx
and ExportTx
.
ExportTx
ExportTx is a transaction to export funds from Coreth to a different chain.
What ExportTx Contains
An ExportTx contains an typeID
, networkID
, blockchainID
, destinationChain
, inputs
, and exportedOutputs
.
typeID
is an int that the type for an ExportTx. The typeID for an exportTx is 1.networkID
is an int that defines which Avalanche network this transaction is meant to be issued to. This could refer to Mainnet, Fuji, etc. and is different than the EVM's network ID.blockchainID
is a 32-byte array that defines which blockchain this transaction was issued to.destinationChain
is a 32-byte array that defines which blockchain this transaction exports funds to.inputs
is an array of EVM Inputs to fund the ExportTx.exportedOutputs
is an array of TransferableOutputs to be transferred todestinationChain
.
Gantt ExportTx Specification
ExportTx Example
Let's make an EVM Output:
TypeID
:1
NetworkID
:12345
BlockchainID
:0x91060eabfb5a571720109b5896e5ff00010a1cfe6b103d585e6ebf27b97a1735
DestinationChain
:0xd891ad56056d9c01f18f43f58b5c784ad07a4a49cf3d1f11623804b5cba2c6bf
Inputs
:"Example EVMInput as defined above"
Exportedoutputs
:"Example TransferableOutput as defined above"
ImportTx
ImportTx is a transaction to import funds to Coreth from another chain.
What ImportTx Contains
An ImportTx contains an typeID
, networkID
, blockchainID
,
destinationChain
, importedInputs
, and Outs
.
typeID
is an int that the type for an ImportTx. The typeID for anImportTx
is 0.networkID
is an int that defines which Avalanche network this transaction is meant to be issued to. This could refer to Mainnet, Fuji, etc. and is different than the EVM's network ID.blockchainID
is a 32-byte array that defines which blockchain this transaction was issued to.sourceChain
is a 32-byte array that defines which blockchain from which to import funds.importedInputs
is an array of TransferableInputs to fund the ImportTx.Outs
is an array of EVM Outputs to be imported to this chain.
Gantt ImportTx Specification
ImportTx Example
Let's make an ImportTx:
TypeID
:0
NetworkID
:12345
BlockchainID
:0x91060eabfb5a571720109b5896e5ff00010a1cfe6b103d585e6ebf27b97a1735
SourceChain
:0xd891ad56056d9c01f18f43f58b5c784ad07a4a49cf3d1f11623804b5cba2c6bf
ImportedInputs
:"Example TransferableInput as defined above"
Outs
:"Example EVMOutput as defined above"
Credentials
Credentials have one possible type: SECP256K1Credential
. Each credential is
paired with an Input. The order of the credentials match the order of the
inputs.
SECP256K1 Credential
A secp256k1 credential contains a list of 65-byte recoverable signatures.
What SECP256K1 Credential Contains
TypeID
is the ID for this type. It is0x00000009
.Signatures
is 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
:0x0acccf47a820549a84428440e2421975138790e41be262f7197f3d93faa26cc8741060d743ffaf025782c8c86b862d2b9febebe7d352f0b4591afbd1a737f8a30010199dbf
Signed Transaction
A signed transaction contains an unsigned AtomicTx
and credentials.
What Signed Transaction Contains
A signed transaction contains a CodecID
, AtomicTx
, and Credentials
.
CodecID
The only current valid codec id is00 00
.AtomicTx
is an atomic transaction, as described above.Credentials
is an array of credentials. Each credential corresponds to the input at the same index in the AtomicTx
Gantt Signed Transaction Specification
Proto Signed Transaction Specification
Signed Transaction Example
Let's make a signed transaction that uses the unsigned transaction and credential from the previous examples.
-
CodecID
:0
-
UnsignedTx
:0x000000000000303991060eabfb5a571720109b5896e5ff00010a1cfe6b103d585e6ebf27b97a1735d891ad56056d9c01f18f43f58b5c784ad07a4a49cf3d1f11623804b5cba2c6bf000000016613a40dcdd8d22ea4aa99a4c84349056317cf550b6685e045e459954f258e5900000001dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db00000005000000746a5288000000000100000000000000010eb5ccb85c29009b6060decb353a38ea3b52cd20000000746a528800dbcf890f77f49b96857648b72b77f9f82937f28a68704af05da0dc12ba53f2db
-
Credentials
0x00000009000000010acccf47a820549a84428440e2421975138790e41be262f7197f3d93faa26cc8741060d743ffaf025782c8c86b862d2b9febebe7d352f0b4591afbd1a737f8a300
UTXO
A UTXO is a standalone representation of a transaction output.
What UTXO Contains
A UTXO contains a CodecID
, TxID
, UTXOIndex
, AssetID
, and Output
.
CodecID
The only validCodecID
is00 00
TxID
is a 32-byte transaction ID. Transaction IDs are calculated by taking sha256 of the bytes of the signed transaction.UTXOIndex
is an int that specifies which output in the transaction specified byTxID
that this utxo was created by.AssetID
is a 32-byte array that defines which asset this utxo references.Output
is the output object that created this utxo. The serialization of Outputs was defined above.
Gantt UTXO Specification
Proto UTXO Specification
UTXO Example
Let's make a UTXO from the signed transaction created above:
CodecID
:0
TxID
:0xf966750f438867c3c9828ddcdbe660e21ccdbb36a9276958f011ba472f75d4e7
UTXOIndex
: 0 = 0x00000000AssetID
:0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
Output
:"Example EVMOutput as defined above"
Last updated on