Overview
Gasless transactions are the future of user onboarding. When users interact with your app for the first time, they shouldn’t need to pay gas just to get started. By using a Paymaster with Smart Wallets on Base, you can sponsor gas fees for onchain interactions—creating a frictionless, seamless experience for your users. In this guide, you’ll learn how to build a reusable component that makes sponsored transactions possible, from allowlisting your contract to wiring up the frontend with Wagmi, Viem, and OnchainKit.Prerequisites
Before you get started, make sure you have the following ready:- A deployed contract (on Base Mainnet or Base Sepolia)
- Viem v2.23.12
- Wagmi v2.14.15
- A Coinbase Developer Platform (CDP) account
- OnchainKit
Please use the specified versions of Wagmi and Viem for full compatibility with Base Wallet.
Allowlist Your Contract
To sponsor gas for your application, you first need to allowlist the contract and function you want to support.- Go to https://portal.cdp.coinbase.com/
- Navigate to Onchain Tools > Paymaster in the left-hand sidebar.
- Under the Configuration tab, click Enable Paymaster, then select Add.
- Input your contract address. For this example, we’ll use:
- Specify the function signature:
startGame(uint256)
- Click Save to finalize the configuration.
Set Up Your Constants File
Let’s set up a file to store important contract data. Create a file atapp/utils/constants.ts
:
Add the Contract ABI
We’ll need the contract ABI to encode the correct function calls.- Create a new directory:
app/utils/abis
- Add a file called
GuessGameABI.ts
inside it. - Paste the ABI you retrieved from a block explorer like Basescan or Blockscout.
You can find verified contract ABIs on Basescan. Navigate to the contract address, go to the Contract tab, and copy the ABI.
Build the Sponsored Transaction Component
Let’s build a reusablePlayButton
component that triggers a sponsored transaction using Wagmi + Viem.
Create a new file: app/components/PlayButton.tsx
Import the necessary modules:
sendCalls
: