This repo has code examples on how to sponsor a mint for a Knight Warriors NFT on Base Sepolia using Coinbase Developer Platform's Paymaster & Bundler. If you'd like to see a live demo app sponsoring NFT mints in action, check out ours here.
We currently have examples for the following SDKs, but contributions are always welcome! See Contributing for more details.
- SimpleAccount (default)
- Safe
- Kernel
SDK | Simple | Safe | Kernel |
---|---|---|---|
aa-core | ✅ | ❌ | ❌ |
permissionless.js | ✅ | ✅ | ✅ |
@zerodev/sdk | ❌ | ❌ | ✅ |
Prerequisites: you'll need to have node and yarn installed.
git clone https://github.com/coinbase/paymaster-bundler-examples.git
cp .env.example .env
yarn
-
This will setup dotenv to load the env file for private values
-
- Navigate to https://www.coinbase.com/developer-platform/products/base-node
- Sign up for a Coinbase Developer Platform account, if you don't have one already.
- Under the Build Onchain section in the Portal, select Node
- In the dropdown on the top right of Configuration, select Base Testnet (Sepolia)
- Copy your RPC endpoint, and paste it into
.env
as theRPC_URL
variable.- The RPC URL should look like
https://api.developer.coinbase.com/rpc/v1/base-sepolia/<api_key>
- The RPC URL should look like
-
You'll need to add a private key to initialize and sign for your ERC-4337 smart contract account
- Since the NFT mint is free and gas will be sponsored by our Paymaster, you can use a new account without any funds
- You can create a new private key with Foundry
- To install Foundry, run
curl -L https://foundry.paradigm.xyz | bash
- To generate a new key pair, run
cast wallet new
- To install Foundry, run
- Copy your private key, and paste it into
.env
as thePRIVATE_KEY
variable
-
- If you're using Pimlico, you can use a different smart account type by changing the
account_type
variable in.env
- Valid values:
simple
,safe
,kernel
- pimlico/src/account.js is a code example on how to configure a different smart account for SDKs that support this feature
- Valid values:
- If you're using Pimlico, you can use a different smart account type by changing the
Example for Alchemy
cd examples/alchemy
yarn
yarn dev
You should receive an Etherscan link with your sponsored transaction in the terminal output. Example
Minting to 0xF19CEA17462220437000F459f721e3e393bd1fc9
Waiting for transaction...
⛽ Successfully sponsored gas for mintTo transaction with Coinbase Developer Platform!
🔍 View on Etherscan: https://sepolia.basescan.org/tx/0xe51e9bf6fea0dfecfcbf7168bcc7da2c833ad0dcac5651940953a89857674885
✨ Done in 5.66s.
If you'd like to see an example of an app sponsoring NFT mints in action, check out our demo app here.