TRANSACTIONS
Last updated
Last updated
Transactions are cryptographically signed instructions from accounts. An account will initiate a transaction to update the state of the BTC20 Smart Chain network. The simplest transaction is transferring BTCC from one account to another.
BTC20 Smart Chain transaction refers to an action initiated by an externally-owned account, in other words an account managed by a human, not a contract. For example, if Bob sends Alice 1 BTCC, Bob's account must be debited and Alice's must be credited. This state-changing action takes place within a transaction.
Transactions, which change the state of the EVM, need to be broadcast to the whole network. Any node can broadcast a request for a transaction to be executed on the EVM; after this happens, a validator will execute the transaction and propagate the resulting state change to the rest of the network.
Transactions require a fee and must be included in a validated block. To make this overview simpler we'll cover gas fees and validation elsewhere.
A submitted transaction includes the following information:
from
– the address of the sender, that will be signing the transaction. This will be an externally-owned account as contract accounts cannot send transactions.
recipient
– the receiving address (if an externally-owned account, the transaction will transfer value. If a contract account, the transaction will execute the contract code)
signature
– the identifier of the sender. This is generated when the sender's private key signs the transaction and confirms the sender has authorized this transaction
nonce
- a sequentially incrementing counter which indicates the transaction number from the account
value
– amount of BTCC to transfer from sender to recipient (denominated in WEI, where 1 BTCC equals 1e+18wei)
input data
– optional field to include arbitrary data
gasLimit
– the maximum amount of gas units that can be consumed by the transaction. The EVM specifies the units of gas required by each computational step
maxPriorityFeePerGas
- the maximum price of the consumed gas to be included as a tip to the validator
maxFeePerGas
- the maximum fee per unit of gas willing to be paid for the transaction (inclusive of baseFeePerGas
and maxPriorityFeePerGas
)
Gas is a reference to the computation required to process the transaction by a validator. Users have to pay a fee for this computation. The gasLimit
, and maxPriorityFeePerGas
determine the maximum transaction fee paid to the validator.
The transaction object will look a little like this:
But a transaction object needs to be signed using the sender's private key. This proves that the transaction could only have come from the sender and was not sent fraudulently.
BTC20 Smart Chain client will handle this signing process.
Example JSON-RPC call:
Example response:
the raw
is the signed transaction in Recursive Length Prefix (RLP) encoded form
the tx
is the signed transaction in JSON form
With the signature hash, the transaction can be cryptographically proven that it came from the sender and submitted to the network.
The vast majority of transactions access a contract from an externally-owned account. Most contracts are written in Solidity and interpret their data field in accordance with the
application binary interface (ABI).
The first four bytes specify which function to call, using the hash of the function's name and arguments. You can sometimes identify the function from the selector using this database(opens in a new tab).
The rest of the calldata is the arguments, encoded as specified in the ABI specs(opens in a new tab).
For example, lets look at this transaction(opens in a new tab). Use Click to see More to see the calldata.
The function selector is 0xa9059cbb
. There are several known functions with this signature(opens in a new tab). In this case the contract source code(opens in a new tab) has been uploaded to btccscan, so we know the function is transfer(address,uint256)
.
The rest of the data is:
According to the ABI specifications, integer values (such as addresses, which are 20-byte integers) appear in the ABI as 32-byte words, padded with zeros in the front. So we know that the to
address is 4f6742badb049791cd9a37ea913f2bac38d01279
(opens in a new tab). The value
is 0x3b0559f4 = 990206452.
On BTC20 Smart Chain there are a few different types of transactions:
Regular transactions: a transaction from one account to another.
Contract deployment transactions: a transaction without a 'to' address, where the data field is used for the contract code.
Execution of a contract: a transaction that interacts with a deployed smart contract. In this case, 'to' address is the smart contract address.
As mentioned, transactions cost gas to execute. Simple transfer transactions require 21000 units of Gas.
So for Bob to send Alice 1 BTCC at a baseFeePerGas
of 190 gwei and maxPriorityFeePerGas
of 10 gwei, Bob will need to pay the following fee:
Bob's account will be debited -1.0042 BTCC (1 BTCC for Alice + 0.0042 BTCC in gas fees)
Alice's account will be credited +1.0 BTCC
The base fee will be burned -0.00399 BTCC
Validator keeps the tip +0.000210 BTCC
Gas is required for any smart contract interaction too.
Any gas not used in a transaction is refunded to the user account.
Once the transaction has been submitted the following happens:
A transaction hash is cryptographically generated: 0x97d99bc7729211111a21b12c933c949d4f31684f1d6954ff477d0477538ff017
The transaction is then broadcasted to the network and added to a transaction pool consisting of all other pending network transactions.
A validator must pick your transaction and include it in a block in order to verify the transaction and consider it "successful".
As time passes the block containing your transaction will be upgraded to "justified" then "finalized". These upgrades make it much more certain that your transaction was successful and will never be altered. Once a block is "finalized" it could only ever be changed by a network level attack that would cost many billions of dollars.