Sui Sponsored Transactions - Basic Integrations Examples

Tutorial

Traditionally, users engaging with decentralized aplications (dApps) face a common hurdle: gas fees. These Sui gas fees in our case, required to execute transactions on the blockchain, often deter new users from fully embracing the potential of Web3. However, Sui innovative sponsored transaction feature eliminates this obstacle, empowering builders to cover the gas fees for their app transactions. This revolutionary functionality paves the way for a seamless user experience, encouraging broader adoption of decentralized applications.

If you have any questions, you can ask them here.

Sponsored Transaction Workflow

Sui's sponsored transaction workflow is a well-orchestrated process that ensures smooth and gas fee-free transactions for end-users. Here's a breakdown of the steps involved.

User Initiates an Action

The process kicks off when a user initializes a GasLessTransactionData transaction, indicating their intent to perform a specific action within a dApp.

dApp Creates a Sui Transaction Block

At the heart of the sponsored transaction workflow lies the dApp's ability to create a Transaction Block. This block encapsulates all the necessary data, including the user's intent, the action to be performed, and any associated parameters.

Transmission of GasLessTransactionData

The GasLessTransactionData is sent to the sponsor, a key participant in the sponsored transaction framework, with a signature request. This data serves as the foundation for the upcoming transaction.

Validation and Transaction Data Construction

The sponsor validates the received transaction and constructs TransactionData, incorporating the necessary gas fees. This step ensures that the transaction is properly funded for execution on the Sui blockchain.

Transaction Signing

The sponsor signs the TransactionData, indicating their approval and commitment to the transaction. The private key required for this signature is securely stored in AWS Secrets Manager, ensuring the utmost security.

Verification and Dual Signing by the User

The signed TransactionData, along with the sponsor's signature, is sent back to the user. The user verifies the transaction details and signs the TransactionData once more, creating a dual-signed transaction ready for execution.

Transaction Execution on Sui

The dual-signed transaction is submitted to the Sui network via a Sui node (full node) or the sponsor. Sui processes the transaction, executing the specified action within the dApp, all without requiring the user to pay any gas fees.

User Notification

Finally, the user is notified by a dApp that the transaction is sponsored and sent.

Implementing Sui Sponsored Transactions: A Developer's Perspective

To implement sponsored transactions, developers interact with the Sui API or Sponsored Transaction API, making use of the sui-sign-sponsored-transaction Lambda function. Here's a glimpse of the client-side code that facilitates this process:

const response = await fetch('http://localhost:5000/blockchain/sui-sign-sponsored-transaction', {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    sender: wallet.address,
    module: libName,
    action,
    arguments: data,
  }),
});

const sponsorSignedTransaction = await response.json();
const transactionBlock = TransactionBlock.from(sponsorSignedTransaction?.transactionBlockBytes);

const senderSignedTransaction = await wallet.signTransactionBlock({
  transactionBlock,
});

const executeResponse = await provider.executeTransactionBlock({
  transactionBlock: sponsorSignedTransaction?.transactionBlockBytes,
  signature: [sponsorSignedTransaction?.signatureBytes, senderSignedTransaction.signature],
  options: { showEffects: true },
  requestType: 'WaitForLocalExecution',
});

This client-side code acts as a bridge between the user, the sponsor, and the Sui blockchain, enabling the seamless execution of gas fee-free transactions.

Conclusion

Sui's sponsored transaction feature represents a paradigm shift in the world of decentralized applications, removing a significant barrier to entry for users. Through our exploration of this innovative functionality, we've gained valuable insights that have shaped our approach to building user-friendly dApps.

Feel free to leave your questions here.

Answers 0