Developer Fundamentals
-- Write Transactions III
Learn how to sign, send, and track VeChainThor transactions, including building signed objects, submitting them to the network, and monitoring results using the SDK.
Sign, Send & Track
Once a transaction is built, it needs to be signed by an entity that will execute all the code. This also makes the origin verifiable.
It is a four-step process:
Get Signer
Sign Transaction
Build Signed Transaction Object
Send & Track Transaction
Let's look at each step in more detail.
1. Get Signer
2. Sign Transaction
And using the signer to sign the transaction:
3. Build Signed Transaction Object
signTransaction returns the fully signed transaction that can already be published using a POST request to the /transactions endpoint of a VeChain node:
For submission by SDK, the raw hex string needs to be restored into a transaction object:
4. Send Transaction
The signed transaction can be published to the network using sendTransaction, which will post the data to the connected node:
Wait for Results
sendTransaction returns a transaction ID that can be used to track the status of the newly published transaction. waitForTransaction will resolve with the full receipt as soon as the result is available:
The snippet below brings it all together and illustrates how you can build a transaction, estimate how much it costs, and sign it to execute the transaction onchain.
The snippet includes:
Necessary packages and imports
Build a transaction
Encoded function calls
Calculate how much gas the transaction costs
Sign the transaction with fee delegation (covered in the next lesson)
Try It Yourself
If you're using your own mnemonic, make sure to fund your wallet with VTHO
If you're using a one-time wallet, the script will fail as we don't have a funded wallet. Move to the Fee Delegation lesson to understand how to delegate gas fees and complete the full script.
Join our Telegram