Gasless NFT Minting
This guide demonstrates how to mint NFTs without paying gas fees using SBC's custom paymaster and bundler. This approach enables gasless NFT minting experiences for your users on Base and Base Sepolia networks.
Prerequisites
- Access to SBC's bundler and paymaster services
Reach out to us on Telegram to access our Paymaster and Bundler.
Contract Addresses
Base Sepolia (Testnet)
- SBC Token:
0xf9FB20B8E097904f0aB7d12e9DbeE88f2dcd0F16
- Sample NFT:
0xb819edABAEccc6E0eE44371a9A2Df019493DBb58
The Sample NFT contract is a standard ERC-721 implementation. View its source code here.
Implementation Steps
1. Create a SimpleAccount smart account from your wallet
const owner = createWalletClient({
account: CurrentConfig.account!.address as Hex,
chain,
transport: custom((window as any).ethereum),
});
const simpleAccount = await toSimpleSmartAccount({
client: localPublicClient,
owner: owner,
entryPoint: {
address: entryPoint07Address,
version: "0.7",
},
});
2. Create a Paymaster Client from our Paymaster URL
// Reach out to us on Telegram https://t.me/stablecoin_xyz to get an API KEY
const PAYMASTER_API_URL = `https://api.aa.stablecoin.xyz/rpc/v1/baseSepolia/${SBC_PAYMASTER_API_KEY}`;
const pmClient = createPaymasterClient({
transport: http(PAYMASTER_API_URL),
});
3. Create the Smart Account Bundler Client with our Paymaster Client
const smartAccountClient = createSmartAccountClient({
account: simpleAccount,
chain: baseSepolia,
bundlerTransport: http(PAYMASTER_API_URL),
paymaster: pmClient,
userOperation: {
estimateFeesPerGas: async () => {
return {
maxFeePerGas: 10n,
maxPriorityFeePerGas: 10n,
};
},
},
});
4. Encode the calldata for the mintNFT
function, then send the user operation
const callData = encodeFunctionData({
abi: nftAbi,
functionName: "mintNFT",
args: [smartAccountClient.account.address],
});
const NFT_CONTRACT_ADDRESS = "0xb819edABAEccc6E0eE44371a9A2Df019493DBb58";
const txHash = await smartAccountClient
.sendTransaction({
account: smartAccountClient.account,
to: NFT_CONTRACT_ADDRESS,
data: callData,
})
.catch((error) => {
console.error("\x1b[31m", `❌ ${error.message}`);
process.exit(1);
});
console.log(" ");
console.log(" ");
console.debug("NFT Minted! Transaction Hash:", txHash);
console.log(" ");
console.log(" ");
Next Steps
- Learn about Zero gas Mass Payment functionality