Gelato
  • Introduction
    • Gelato, The Web3 Cloud Platform
  • Smart Wallets
    • Introduction
      • Understanding EIP-7702
      • Understanding ERC-4337
      • ERC-4337 vs EIP-7702
    • Templates & Examples
    • How-To Guides
      • Sponsor gas for your users
      • Allow users to pay gas with erc20
      • Allow users to pay gas with native
      • Use Dynamic/Privy signers with React SDK
      • Estimate Gas for your transactions
    • React SDK
    • Demo
    • Supported Networks
  • Rollup As A Service
    • Introduction
    • Rollup Stacks
      • Arbitrum Orbit
        • Run a Full Orbit Node
      • OP Stack
        • Run OP Node
    • Deploy your Rollup
    • Customization
      • Data Availability
        • Celestia
        • Avail
        • Eigen DA
      • Custom Gas Token
      • Marketplace
        • Gelato Services
        • Data Indexers
        • Block Explorers
        • Oracles
        • Bridges
        • Account Abstraction
        • On & Off-ramp
        • Community
        • Identity & KYC
        • Others
      • Verifier Node Package
    • Public Testnet
  • RPC Nodes
    • Introduction
    • Compute Units
    • Using RPC Nodes
    • Supported Networks
    • Pricing and Plans
    • FAQ
  • Web3 Services
    • Web3 Functions
      • Understanding Web3 Functions
        • Trigger Types
        • Typescript Function
        • Solidity Function
        • Automated Transactions
      • Security Considerations
      • Template & Use Cases
      • Quick Start
        • Writing Typescript Functions
          • Event Trigger
          • Private Typescript Functions
          • Callbacks
        • Test, Deploy & Run Typescript functions
        • Writing Solidity Functions
        • Test, Deploy & Run Solidity Functions
        • Initiate an Automated Transaction
      • Create a Web3 Function Task
        • Using the UI
        • Using the Safe App
        • Using a Smart Contract
        • Using the Automate SDK
      • Analytics & Monitoring
      • Supported Networks
      • Subscription & Payments
      • Legacy Automate Migration Guide
    • Relay
      • What is Relaying?
      • Security Considerations
        • ERC-2771 Delegatecall Vulnerability
      • Templates
      • Quick Start
        • Sponsored Calls
        • Non-Sponsored Calls
      • ERC-2771 (recommended)
        • SponsoredCallERC2771
        • CallWithSyncFeeERC2771
          • Relay Context Contracts ERC2771
      • Non-ERC-2771
        • SponsoredCall
        • CallWithSyncFee
          • Relay Context Contracts
      • Relay API
      • Gelato's Fee Oracle
      • Tracking your Relay Request
      • Supported Networks
      • Subscriptions and Payments
        • 1Balance & Relay
        • SyncFee Payment Tokens
        • Relay Pricing
      • ERC2771 Migration Guide
    • VRF
      • Understanding VRF
      • How does Gelato VRF Work?
      • Security Considerations
      • Template
      • Quick Start
      • Create a VRF Task
        • Create a Fallback VRF
        • Migrating from Chainlink VRF
      • Supported Networks
      • Pricing & Rate Limits
    • Oracles
      • Understanding Gelato Oracles
      • Quick Start
      • Data Providers
        • Stork
        • Choas Labs
      • Migrating from Chainlink Oracles
      • Available Price Feeds
      • Supported Networks
      • Pricing & Rate Limits
    • Account Abstraction
      • Understanding ERC-4337
      • Introduction to Gelato Bundler
      • Templates & Examples
      • Quick Start
      • Supported Networks
      • Bundler API Endpoints
        • eth_sendUserOperation
        • eth_estimateUserOperationGas
        • eth_getUserOperationByHash
        • eth_getUserOperationReceipt
        • eth_supportedEntryPoints
        • eth_maxPriorityFeePerGas
        • eth_chainId
    • 1Balance
      • 1Balance Alerts
      • Subscription Plans
      • Subscription Notifications
      • USDC Addresses
    • AI Agents
    • Teams
  • GELATO DAO
    • DAO & Token (GEL)
    • GEL Token Contracts
    • Governance Process
  • Social Media
Powered by GitBook
On this page
  • Installation
  • Getting started
  • 1. Importing dependencies
  • 2. Setting up Smart Wallet Context Provider for different Wallet Providers
  • 3. Setting up Connect Button
  • 4. Fetching Smart Wallet Client from Smart Wallet Context
  • 5. Sending Transactions
  1. Smart Wallets
  2. How-To Guides

Use Dynamic/Privy signers with React SDK

PreviousAllow users to pay gas with nativeNextEstimate Gas for your transactions

Last updated 19 hours ago

Curious about what our React SDK includes and the features it provides? Explore the full overview .

Installation

npm install @gelatonetwork/smartwallet-react-sdk viem wagmi
yarn add @gelatonetwork/smartwallet-react-sdk viem wagmi
pnpm install @gelatonetwork/smartwallet-react-sdk viem wagmi

Getting started

1. Importing dependencies

import {
  GelatoSmartWalletContextProvider,
  useGelatoSmartWalletProviderContext,
  GelatoSmartWalletConnectButton,
  dynamic,
  privy,
  wagmi,
} from "@gelatonetwork/smartwallet-react-sdk";

import { sponsored, native, erc20 } from "@gelatonetwork/smartwallet";
import { baseSepolia } from "viem/chains";
import { http } from "wagmi";

2. Setting up Smart Wallet Context Provider for different Wallet Providers

To create a Sponsor API Key, visit the Gelato App and navigate to the Relay section. Create a new app, select the required networks, and copy the generated Sponsor API Key.

<GelatoSmartWalletContextProvider
      settings={{
        apiKey: process.env.SPONSOR_API_KEY as string,
        waas: dynamic(
          process.env.NEXT_PUBLIC_DYNAMIC_ENVIRONMENT_ID as string
        ),
        wagmi: wagmi({
          chains: [baseSepolia],
          transports: {
            [baseSepolia.id]: http(),
          },
        }),
      }}
  >
      {children}
</GelatoSmartWalletContextProvider>
<GelatoSmartWalletContextProvider
      settings={{
        apiKey: process.env.SPONSOR_API_KEY as string,
        waas: privy(
          process.env.NEXT_PUBLIC_PRIVY_ENVIRONMENT_ID as string
        ),
        wagmi: wagmi({
          chains: [baseSepolia],
          transports: {
            [baseSepolia.id]: http(),
          },
        }),
      }}
  >
      {children}
</GelatoSmartWalletContextProvider>

3. Setting up Connect Button

You can customize the appearance of your connect button here. This button triggers the wallet connectors widget configured for the UI.

const children = (
  <div classname="mt-2 text-white">Get Started!</div>
) as React.ReactElement;

export const Login = () => (
  <GelatoSmartWalletConnectButton>{children}</GelatoSmartWalletConnectButton>
);

4. Fetching Smart Wallet Client from Smart Wallet Context

Use this client directly to execute transactions with different gas payment methods. Additionally, a logout option is available to disconnect your connected wallet.

const {
    gelato: { client },
    logout,
  } = useGelatoSmartWalletProviderContext();

5. Sending Transactions

You can send transactions using different gas payment methods as shown below. Additionally, you can add multiple transactions to the calls array to batch them and send them on-chain in a single request.

const results = await client.execute({
    payment : sponsored(),
    calls: [
      {
        to: "0xa8851f5f279eD47a292f09CA2b6D40736a51788E",
        data: "0xd09de08a",
        value: 0n
      }
    ]
});

console.log("userOp hash:", results?.id);
const txHash = await results?.wait();
console.log("transaction hash",txHash);
const token = "0x036CbD53842c5426634e7929541eC2318f3dCF7e"; // USDC (Base Sepolia)
const results = await client.execute({
    payment: erc20(token),
    calls: [
      {
        to: "0xa8851f5f279eD47a292f09CA2b6D40736a51788E",
        data: "0xd09de08a",
        value: 0n
      }
    ]
});

console.log("userOp hash:", results?.id);
const txHash = await results?.wait();
console.log("transaction hash",txHash);
const results = await client.execute({
    payment : native(),
    calls: [
      {
        to: "0xa8851f5f279eD47a292f09CA2b6D40736a51788E",
        data: "0xd09de08a",
        value: 0n
      }
    ]
});

console.log("userOp hash:", results?.id);
const txHash = await results?.wait();
console.log("transaction hash",txHash);

For detailed instructions, click to learn more about creating a Sponsor API Key.

Check out the complete example React app demonstrating the integration of Dynamic as the wallet provider .

here
here
here
npm: @gelatonetwork/smartwallet-react-sdknpm
Logo