Skip to main content

3 posts tagged with "dApp"

Decentralized applications

View all tags

Building Gas-less Experiences with Sui Paymaster: Architecture and Implementation Guide

· 10 min read
Dora Noda
Software Engineer

Imagine a world where users can interact with your dApp seamlessly, without needing to hold any native tokens (SUI). This is no longer a distant dream. With Sui's Gas Station (also known as a Paymaster), developers can cover gas fees on behalf of their users, completely removing one of the biggest barriers for new entrants to Web3 and enabling a truly frictionless on-chain experience.

This article provides a complete guide to upgrading your dApp to be gas-less. We'll dive deep into the core concepts of the Sui Paymaster, its architecture, implementation patterns, and best practices.

1. Background and Core Concepts: What is a Sponsored Transaction?

In the world of blockchain, every transaction requires a network fee, or "gas." For users accustomed to the seamless experiences of Web2, this is a significant cognitive and operational hurdle. Sui addresses this challenge at the protocol level with Sponsored Transactions.

The core idea is simple: allow one party (the Sponsor) to pay the SUI gas fees for another party's (the User) transaction. This way, even if a user has zero SUI in their wallet, they can still successfully initiate on-chain actions.

Paymaster ≈ Gas Station

In the Sui ecosystem, the logic for sponsoring transactions is typically handled by an off-chain or on-chain service called a Gas Station or Paymaster. Its primary responsibilities include:

  1. Evaluating the Transaction: It receives a user's gas-less transaction data (GasLessTransactionData).
  2. Providing Gas: It locks and allocates the necessary gas fee for the transaction. This is usually managed through a gas pool composed of many SUI Coin objects.
  3. Generating a Sponsor Signature: After approving the sponsorship, the Gas Station signs the transaction with its private key (SponsorSig), certifying its willingness to pay the fee.
  4. Returning the Signed Transaction: It sends back the TransactionData, which now includes the gas data and the sponsor's signature, to await the user's final signature.

In short, a Gas Station acts as a refueling service for your dApp's users, ensuring their "vehicles" (transactions) can travel smoothly on the Sui network.

2. High-Level Architecture and Interaction Flow

A typical gas-less transaction involves coordination between the user, the dApp frontend, the Gas Station, and a Sui Full Node. The interaction sequence is as follows:

Flow Breakdown:

  1. The User performs an action in the dApp UI, which constructs a transaction data package without any gas information.
  2. The dApp sends this data to its designated Gas Station to request sponsorship.
  3. The Gas Station verifies the request's validity (e.g., checks if the user is eligible for sponsorship), then populates the transaction with a Gas Coin and its signature, returning the semi-complete transaction to the dApp.
  4. The User sees the full transaction details in their wallet (e.g., "Purchase one NFT") and provides the final signature. This is a crucial step that ensures the user maintains consent and control over their actions.
  5. The dApp broadcasts the complete transaction, containing both the user's and the sponsor's signatures, to a Sui Full Node.
  6. After the transaction is finalized on-chain, the Gas Station can confirm this by listening for on-chain events or receipts, then notify the dApp backend via a webhook to close the loop on the business process.

3. Three Core Interaction Models

You can use the following three interaction models individually or in combination to suit your business needs.

Model 1: User-Initiated → Sponsor-Approved (Most Common)

This is the standard model, suitable for the vast majority of in-dApp interactions.

  1. User constructs GasLessTransactionData: The user performs an action within the dApp.
  2. Sponsor adds GasData and signs: The dApp backend sends the transaction to the Gas Station, which approves it, attaches a Gas Coin, and adds its signature.
  3. User reviews and gives final signature: The user confirms the final transaction details in their wallet and signs it. The dApp then submits it to the network.

This model strikes an excellent balance between security and user experience.

Model 2: Sponsor-Initiated Airdrops/Incentives

This model is perfect for airdrops, user incentives, or batch asset distributions.

  1. Sponsor pre-fills TransactionData + signs: The Sponsor (typically the project team) pre-constructs most of the transaction (e.g., airdropping an NFT to a specific address) and attaches its sponsorship signature.
  2. User's second signature makes it effective: The user only needs to sign this "pre-approved" transaction once for it to be executed.

This creates an extremely smooth user experience. With just one click to confirm, users can claim rewards or complete tasks, dramatically increasing the conversion rates of marketing campaigns.

Model 3: Wildcard GasData (Credit Line Model)

This is a more flexible and permission-based model.

  1. Sponsor transfers a GasData object: The Sponsor first creates one or more Gas Coin objects with a specific budget and transfers ownership directly to the user.
  2. User spends freely within the budget: The user can then freely use these Gas Coins to pay for any transactions they initiate within the budget's limits and validity period.
  3. Gas Coin is returned: Once depleted or expired, the Gas Coin object can be designed to be automatically destroyed or returned to the Sponsor.

This model is equivalent to giving the user a limited-time, limited-budget "gas fee credit card," suitable for scenarios requiring a high degree of user autonomy, such as offering a free-to-play experience during a game season.

4. Typical Application Scenarios

The power of the Sui Paymaster lies not just in solving the gas fee problem, but also in its ability to deeply integrate with business logic to create new possibilities.

Scenario 1: Paywalls

Many content platforms or dApp services require users to meet certain criteria (e.g., hold a VIP NFT, reach a certain membership level) to access features. The Paymaster can implement this logic perfectly.

  • Flow: A user requests an action → the dApp backend verifies the user's qualifications (e.g., NFT ownership) → if eligible, it calls the Paymaster to sponsor the gas fee; if not, it simply denies the signing request.
  • Advantage: This model is inherently resistant to bots and abuse. Since the sponsorship decision is made on the backend, malicious users cannot bypass the qualification check to drain gas funds.

Scenario 2: One-Click Checkout

In e-commerce or in-game purchase scenarios, simplifying the payment process is critical.

  • Flow: The user clicks "Buy Now" on a checkout page. The dApp constructs a transaction that includes the business logic (e.g., transfer_nft_to_user). The user only needs to sign to approve the business transaction in their wallet, without worrying about gas. The gas fee is covered by the dApp's Sponsor.
  • Advantage: You can encode business parameters like an order_id directly into the ProgrammableTransactionBlock, enabling precise on-chain attribution for backend orders.

Scenario 3: Data Attribution

Accurate data tracking is fundamental to business optimization.

  • Flow: When constructing the transaction, write a unique identifier (like an order_hash) into the transaction's parameters or into an event that will be emitted upon execution.
  • Advantage: When the Gas Station receives the on-chain receipt for a successful transaction, it can easily extract this order_hash by parsing the event or transaction data. This allows for a precise mapping between on-chain state changes and specific backend orders or user actions.

5. Code Skeleton (Based on the Rust SDK)

Here is a simplified code snippet demonstrating the core interaction steps.

// Assume tx_builder, sponsor, and wallet have been initialized

// Step 1: On the user or dApp side, construct a gas-less transaction
let gasless_transaction_data = tx_builder.build_gasless_transaction_data(false)?;

// Step 2: On the Sponsor (Gas Station) side, receive the gasless_transaction_data,
// fill it with a Gas Coin, and return the transaction data with the Sponsor's signature.
// The sponsor_transaction_block function handles gas allocation and signing internally.
let sponsored_transaction = sponsor.sponsor_transaction_block(gasless_transaction_data, user_address, gas_budget)?;

// Step 3: The dApp sends the sponsored_transaction back to the user,
// who signs and executes it with their wallet.
let response = wallet.sign_and_execute_transaction_block(&sponsored_transaction)?;

For a complete implementation, refer to the official Sui documentation's Gas Station Tutorial which offer out-of-the-box code examples.

6. Risks and Protection

While powerful, deploying a Gas Station in a production environment requires careful consideration of the following risks:

  • Equivocation (Double-Spending): A malicious user might try to use the same Gas Coin for multiple transactions in parallel, which would cause the Gas Coin to be locked by the Sui network. This can be effectively mitigated by assigning a unique Gas Coin per user or transaction, maintaining a blacklist, and rate-limiting signing requests.
  • Gas Pool Management: In high-concurrency scenarios, a single large-value Gas Coin can become a performance bottleneck. The Gas Station service must be capable of automatically splitting large SUI Coins into many smaller-value Gas Coins and efficiently reclaiming them after use. Professional Gas Station providers like Shinami offer mature, managed solutions for this.
  • Authorization and Rate Limiting: You must establish strict authorization and rate-limiting policies. For instance, manage sponsorship limits and frequencies based on user IP, wallet address, or API tokens to prevent the service from being drained by malicious actors.

7. Ecosystem Tools

The Sui ecosystem already offers a rich set of tools to simplify Paymaster development and deployment:

  • Official SDKs (Rust/TypeScript): Include high-level APIs like sponsor_transaction_block(), significantly reducing integration complexity.
  • Shinami Gas Station: Provides an all-in-one managed service, including automated Gas Coin splitting/reclaiming, detailed metrics monitoring, and webhook notifications, allowing developers to focus on business logic.
  • Enoki / Mysten Demos: The community and Mysten Labs also provide open-source Paymaster implementations that can be used as a reference for building your own service.

8. Implementation Checklist

Ready to upgrade your dApp to the gas-less era? Go through this checklist before you start:

  • Plan Your Funding Flow: Define the Sponsor's funding source, budget, and replenishment strategy. Set up monitoring and alerts for key metrics (e.g., gas pool balance, consumption rate).
  • Reserve Attribution Fields: When designing your transaction parameters, be sure to reserve fields for business identifiers like order_id or user_id.
  • Deploy Anti-Abuse Policies: You must implement strict authorization, rate-limiting, and logging mechanisms before going live.
  • Rehearse on Testnet: Whether building your own service or integrating a third-party Gas Station, always conduct thorough concurrency and stress testing on a testnet or devnet first.
  • Continuously Optimize: After launch, continuously track transaction success rates, failure reasons, and gas costs. Fine-tune your budget and strategies based on the data.

Conclusion

The Sui Paymaster (Gas Station) is more than just a tool for covering user gas fees. It's a powerful paradigm that elegantly combines a "zero SUI on-chain" user experience with the business need for "order-level on-chain attribution" within a single, atomic transaction. It paves the way for Web2 users to enter Web3 and provides developers with unprecedented flexibility for business customization.

With an increasingly mature ecosystem of tools and the current low gas costs on the Sui network, there has never been a better time to upgrade your dApp's payment and interaction flows to the gas-less era.

Introducing Blockroma - Your Open-source, EVM-Compatible Blockchain Explorer

· 3 min read
Dora Noda
Software Engineer

In today's digital era, blockchain technology has become a crucial part of online transactions and data sharing. As the use of blockchain expands, so does the need for an efficient and transparent way to navigate its ecosystem. Enter Blockroma, an open-source, EVM-compatible blockchain explorer, fulfilling this necessity effectively and efficiently.

Introducing Blockroma - Your Open-source, EVM-Compatible Blockchain Explorer

What is Blockroma?

A blockchain explorer like Blockroma is a web tool that allows users to interact with the blockchain network, providing real-time data, transaction history, and network status. It aids users in understanding individual transactions - including sender, receiver, amount, and transaction time - and provides insights into the blockchain network's current state.

The Tech Stack

Blockroma utilizes a modern technology stack - TypeScript, React, and PostgreSQL - that ensures scalability and easy maintainability. It empowers you with its quick and straightforward deployment process, contributing to a seamless user experience.

Advanced Features

Blockroma steps beyond traditional blockchain explorers, offering advanced features such as searching for specific transactions or addresses, facilitating the creation and viewing of smart contracts, and exploring the history of particular blocks. These features allow users from all backgrounds - developers, traders, investors, or everyday users - to comprehend the blockchain network better and leverage its full potential.

Introducing Blockroma

Why Choose Blockroma?

  • Transparency: Blockroma simplifies the process of accessing blockchain data, enabling users to verify transactions, addresses, and other data effortlessly.
  • Real-time data: It provides real-time data on transaction confirmations, network status, and mining difficulty, which are essential for those needing to monitor the blockchain's health and performance.
  • Searchability: Blockroma's advanced search feature improves the tracking and analysis of blockchain activities by allowing users to search for specific transactions, addresses, or blocks.
  • Security: Enhancing security on the blockchain, Blockroma helps users verify the authenticity of transactions and the identities of the parties involved, providing an added layer of assurance for businesses.

Additional Benefits

Apart from these features, Blockroma also provides custom themes, premium support, and priority updates for managed hosting on Blockroma.com. Moreover, it allows a worry-free experience with zero operation costs.

Conclusion

In a nutshell, Blockroma makes blockchain navigation easier, efficient, and secure for individuals and businesses. With its advanced features and user-friendly interface, Blockroma stands as a robust solution for exploring and interacting with the blockchain. Embrace the future of blockchain interaction with Blockroma.

An Exploration of a16z Crypto Startup School Projects

· 5 min read
Dora Noda
Software Engineer

Andreesen Horowitz, more commonly known as a16z, is a name that reverberates through the halls of venture capital with an aura of visionary innovation. An essential branch of their investment activities, a16z crypto, focuses explicitly on the burgeoning field of crypto and web3 startups, an area that is quickly redefining how we view digital commerce, privacy, and online interaction. Their venture into this domain is more than merely a business move—it is a commitment to shaping the contours of the rapidly evolving Web3 landscape.

The a16z Crypto Startup School, a twelve-week accelerator program, is designed around the specific needs of web3 startups, imparting crucial knowledge, resources, and support. Recently, this initiative showcased an intriguing array of 11 ambitious projects, each aiming to disrupt various sectors through blockchain and Web3 technologies. For the curious, every bit of detail is available on the a16z crypto startup school page.

An Exploration of a16z Crypto Startup School Projects

Demo Projects

These projects not only provide a glimpse into the future of various industries but also offer valuable insights from both a builder's and investor's perspective. They represent practical use cases of blockchain technology and the ways it can innovate systems and processes. Here is a brief overview:

  1. Blockus: With the intent of revolutionizing the gaming economy, Blockus is developing a comprehensive solution for game studios to focus on gameplay more effectively.

  2. ChainPatrol.io: This project aims to bolster Web3 security, offering real-time protection for Web3 communities and raising the bar for digital asset security.

  3. mbd.xyz: This ambitious endeavor seeks to democratize AI recommendation systems, pioneering the concept of the 'Curation Economy', potentially reshaping online content consumption.

  4. Web3Analytic: In an era of data-driven decisions, Web3Analytic provides no-code user analytics solutions that can enhance product performance and user experience.

  5. KIKI world: This innovative project is set to disrupt the beauty industry, promoting a model of co-creation and co-ownership of beauty products with enthusiasts.

  6. formless: Formless proposes a transformation of the media distribution ecosystem by monetizing intellectual property through smart contracts, offering a potentially game-changing method for content creators to benefit from their work.

  7. Fuul.xyz: Addressing the need for streamlined affiliate marketing in the Web3 space, Fuul.xyz aspires to build a bridge between content creators and Web3 projects.

  8. frens: This communications super app aims to foster transactions with friends, protocols, and smart contracts within the conversation, representing an innovative blend of social networking and Web3.

  9. Discove: Discove is exploring a unique protocol for composable mini-apps, presenting a novel approach to Web3 applications that could enhance their utility and ease of use.

  10. Stackr Labs: By offering a unique modular rollup SDK, Stackr Labs allows developers to focus on state machine building, streamlining the development process in the Web3 space.

  11. Sky Lab: Sky Lab envisions an autonomous world, focusing on building games on top of initial world primitives. This could redefine the interactive experience in gaming and beyond.

Categorization

Given the diverse array of projects presented at the a16z Crypto Startup School, they can be categorized based on the industry or sector they primarily target. Here's a possible categorization:

  1. Gaming and Entertainment: This category includes projects that are focused on innovating within the gaming industry, leveraging blockchain and Web3 technologies to enhance user experience, game design, and monetization. Project included: Blockus, Sky Lab.

  2. Security and Infrastructure: Projects that primarily aim to enhance the security and infrastructure of the Web3 space. This includes everything from data protection to the development of key tools and software that can be used by other Web3 services. Projects included: ChainPatrol.io, Stackr Labs.

  3. Data Analytics and AI: These projects focus on leveraging data and AI for various purposes like enhancing product performance and user experience, as well as democratizing AI recommendation systems. Projects included: Web3Analytic, mbd.xyz.

  4. Content Creation and Media Distribution: These projects look at the ways in which content is created and distributed, particularly in terms of intellectual property and how creators are compensated for their work. Project included: formless, KIKI world.

  5. Marketing and Communication: Projects focusing on improving communication within the Web3 space, fostering transactions, and enhancing affiliate marketing for Web3 projects. Projects included: Fuul.xyz, frens.

  6. Web3 Applications and Platforms: Projects that are working on novel applications and platforms within the Web3 space, particularly in terms of their design and user interface. Project included: Discove.

Each of these categories represents a unique approach to the utilization of blockchain and Web3 technology, providing insights into the diverse range of applications these technologies can offer across different sectors.

Conclusion

The rise of Web3 is a fascinating, complex phenomenon and projects such as these, supported by the likes of a16z Crypto Startup School, are contributing to this dynamic evolution. For a more in-depth exploration of each project, the a16z Crypto Startup School page provides comprehensive details.