A simple example demonstrating gasless USDC transfers on Sui using Dynamic wallet integration and transaction sponsorship.
- 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
- User Creates Transaction: User enters recipient address and USDC amount
- Transaction Building: Frontend builds the transaction without gas information
- Gas Sponsorship: Backend API adds gas payment and sponsor signature
- User Signing: User signs the sponsored transaction
- Execution: Transaction is executed with both signatures
- Node.js 18+ or Bun
- Sui testnet account with USDC
- Sponsor wallet with SUI for gas payment
Create a .env.local
file:
FEE_PAYER_PRIVATE_KEY=your_sponsor_private_key_here
# Install dependencies
bun install
# Run development server
bun run dev
- Create a new Sui wallet for gas sponsorship
- Fund it with SUI on testnet
- Export the private key and add it to
.env.local
- Connect your wallet using Dynamic
- Enter recipient address and USDC amount
- Click "Send USDC" to initiate gasless transfer
- Approve the transaction in your wallet
- Wait for confirmation
- Send.tsx: Main component handling transaction creation and user interaction
- Dynamic Integration: Uses Dynamic SDK for wallet connection and signing
/api/gas
: Handles transaction sponsorship and gas payment- Transaction Reconstruction: Rebuilds transactions with gas information
- Sponsor Signing: Signs transactions with sponsor private key
- Transaction Creation: Uses Sui SDK Transaction builder
- Coin Management: Handles multiple USDC coins and merging
- Gas Sponsorship: Backend adds gas payment objects
- Multi-signature: Both user and sponsor signatures required
- Execution: Transaction submitted to Sui network
- Testnet: Currently configured for Sui testnet
- Mainnet: Can be configured by changing RPC URL
@dynamic-labs/sdk-react-core
: Dynamic wallet integration@dynamic-labs/sui
: Sui wallet support@mysten/sui
: Sui SDK for transaction buildingnext
: React frameworkbun
: Package manager and runtime
- Sponsor private key should be kept secure
- Consider rate limiting for production use
- Monitor sponsor wallet balance
- Implement proper error handling
// 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.