Transactions
Transactions related functions.
Transactions
Example: Signing and Decoding
// 1 - Define clauses
const clauses: TransactionClause[] = [
Clause.transferVET(
Address.of('0x7567d83b7b8d80addcb281a71d54fc7b3364ffed'),
VET.of(10000)
) as TransactionClause
];
// 2 - Calculate intrinsic gas of clauses
const gas = HexUInt.of(Transaction.intrinsicGas(clauses).wei).toString();
// 3 - Body of transaction
const body: TransactionBody = {
chainTag: networkInfo.mainnet.chainTag,
blockRef: '0x0000000000000000',
expiration: 0,
clauses,
gasPriceCoef: 128,
gas,
dependsOn: null,
nonce: 12345678
};
// Create private key
const privateKey = await Secp256k1.generatePrivateKey();
// 4 - Sign transaction
const signedTransaction = Transaction.of(body).sign(privateKey);
// 5 - Encode transaction
const encodedRaw = signedTransaction.encoded;
// 6 - Decode transaction
const decodedTx = Transaction.decode(encodedRaw, true);Example: Multiple Clauses
Example: Fee Delegation
Example: BlockRef and Expiration
Example: Transaction Dependency
Example: Transaction Simulation
Complete examples
Errors handling on transactions
Decoding revert reason when simulating a transaction
Last updated
Was this helpful?