Skip to content

dynamic-labs/sui-gasless

Repository files navigation

Sui Gasless USDC Transfer

A simple example demonstrating gasless USDC transfers on Sui using Dynamic wallet integration and transaction sponsorship.

Features

  • Gasless Transactions: Users can send USDC without paying gas fees
  • Dynamic Wallet Integration: Seamless wallet connection using Dynamic
  • Transaction Sponsorship: Backend API handles gas payment for users
  • Real-time Balance Updates: Automatic balance refresh after transactions
  • Progress Tracking: Visual progress indicators for transaction stages

How It Works

  1. User Creates Transaction: User enters recipient address and USDC amount
  2. Transaction Building: Frontend builds the transaction without gas information
  3. Gas Sponsorship: Backend API adds gas payment and sponsor signature
  4. User Signing: User signs the sponsored transaction
  5. Execution: Transaction is executed with both signatures

Setup

Prerequisites

  • Node.js 18+ or Bun
  • Sui testnet account with USDC
  • Sponsor wallet with SUI for gas payment

Environment Variables

Create a .env.local file:

FEE_PAYER_PRIVATE_KEY=your_sponsor_private_key_here

Installation

# Install dependencies
bun install

# Run development server
bun run dev

Sponsor Wallet Setup

  1. Create a new Sui wallet for gas sponsorship
  2. Fund it with SUI on testnet
  3. Export the private key and add it to .env.local

Usage

  1. Connect your wallet using Dynamic
  2. Enter recipient address and USDC amount
  3. Click "Send USDC" to initiate gasless transfer
  4. Approve the transaction in your wallet
  5. Wait for confirmation

Technical Details

Frontend Components

  • Send.tsx: Main component handling transaction creation and user interaction
  • Dynamic Integration: Uses Dynamic SDK for wallet connection and signing

Backend API

  • /api/gas: Handles transaction sponsorship and gas payment
  • Transaction Reconstruction: Rebuilds transactions with gas information
  • Sponsor Signing: Signs transactions with sponsor private key

Transaction Flow

  1. Transaction Creation: Uses Sui SDK Transaction builder
  2. Coin Management: Handles multiple USDC coins and merging
  3. Gas Sponsorship: Backend adds gas payment objects
  4. Multi-signature: Both user and sponsor signatures required
  5. Execution: Transaction submitted to Sui network

Supported Networks

  • Testnet: Currently configured for Sui testnet
  • Mainnet: Can be configured by changing RPC URL

Dependencies

  • @dynamic-labs/sdk-react-core: Dynamic wallet integration
  • @dynamic-labs/sui: Sui wallet support
  • @mysten/sui: Sui SDK for transaction building
  • next: React framework
  • bun: Package manager and runtime

Security Considerations

  • Sponsor private key should be kept secure
  • Consider rate limiting for production use
  • Monitor sponsor wallet balance
  • Implement proper error handling

Example Transaction

// Create transaction
const tx = new Transaction();
tx.setSender(userAddress);

// Split USDC coin
const [coinToSend] = tx.splitCoins(mergedCoin, [amount]);

// Transfer to recipient
tx.transferObjects([coinToSend], recipientAddress);

// Build without gas info
const kindBytes = await tx.build({ onlyTransactionKind: true });

This example demonstrates a complete gasless transaction system that can be used as a reference for building similar applications on Sui.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published