The Transaction Builder
The transaction builder is a simple program that takes the raw transaction bytes, sponsor signature, and user address as parameters, sends the transaction to the IOTA network, and returns the result.
To make it dynamic, we will use the clap
crate to parse the command-line arguments.
init
a new rust project, different from the Gas Station server, and add the following dependencies to your Cargo.toml
file:
loading...
iota/docs/content/developer/tutorials/gas-station-server.mdx iota/docs/content/developer/tutorials/media-platform-package.mdx iota/docs/content/developer/tutorials/sponsored-txs.mdx iota/docs/content/developer/tutorials/transaction-builder.mdx
In the src/main.rs
file, add the logic for the construct_tx
function:
loading...
The construct_tx
function will try to decode the provided transaction bytes and the sponsor's signature. Then, it will sign the transaction with the sender's keystore, send it to the IOTA network, and print the response.
Now that we have the tx_bytes
and sponsor_sig
from the Gas Station server, we can use the construct_tx
function to send the transaction to the IOTA network:
When executing the following command, replace values with actual values from the Gas Server response. Also, try to use a different address for the sponsor address that has no funds
cargo run -- --keystore <KEYSTORE-PATH> --encoded-sig "AA15MUFqu8BQX3zWINWVewS5Ci0QeoCLp1AEffmZmzc8w+tnvVAS7gVkHRh61pdyNe+H4NdseUvwW9yLnchqkQ3p1vxEC3McO9IvqEI8BXaHBgCUFx3DXTO+QWmQKwj2uA==" --encoded-tx "AAACAAVNdXNpYwEBsFI25soGfj+hFLqxVY815ECX4AeKpoF2H6piIghYoXYOFAAAAAAAAAEBACBp6RyDMzUL32u9KZEmatM5knV9t69IKRrbWOelsOGqH3Nwb25zb3JlZF90cmFuc2FjdGlvbnNfcGFja2FnZXMKZnJlZV90cmlhbAACAQAAAQEAx9FYqbBcbf0HwjNknJ4PeDINBm5awOj1EB3lAK2ehOgBOeqaP5iJwfw9edY9l64pOnSFnQzguHbAkCEUceNwZ7sOFAAAAAAAACBC3cFbtd21gUyztwvt5k6hwgXZg7/nTKjNvH5WoXR0078pPO0lkxGM0jHxB/NBuxrZ2znNBJe/8p01VzDPTivC6AMAAAAAAABAS0wAAAAAAAA=" --sender-addr 0xc7d158a9b05c6dfd07c233649c9e0f78320d066e5ac0e8f5101de500ad9e84e8
For the full code of the transaction builder and argument parser, you can check the Transaction builder implementation
Conclusion
This tutorial marks the first part of our journey into implementing sponsored transactions on the IOTA network. We explored the backend architecture, including creating a Move-based package for managing subscriptions, setting up a Gas Station server for transaction sponsorship, and building a transaction submission tool using the IOTA Rust SDK. This backend workflow demonstrates how to abstract gas fees for users, providing a seamless onboarding experience for new users on the IOTA network.
In the second part, we will focus on building the front-end application. This will allow users to interact with the platform, request sponsored transactions, and subscribe to content types. The front-end will serve as the user-facing layer, completing the workflow and ensuring a smooth user experience.
By the end of this series, you'll have a comprehensive understanding of how to build decentralized applications that integrate sponsored transactions, utilizing the full power of the IOTA ecosystem.