Minting Tokens
Interact with smart contracts using RISE Wallet
Minting Tokens
This example demonstrates how to interact with a smart contract on RISE. Because RISE Wallet users often start without gas, transactions are sponsored by the relay infrastructure.
Mint Tokens
Mock USD
0x044b...7f5018 decimals
Mock Token
0x6166...6ceD18 decimals
"use client";import { MintableERC20ABI } from "@/abi/erc20";import { useAccount, useSendCalls } from "wagmi";import { encodeFunctionData } from "viem";export function MintWidget() { const { address } = useAccount(); const { sendCallsAsync } = useSendCalls(); const handleMint = async (tokenAddress) => { // 1. Encode the function call const data = encodeFunctionData({ abi: MintableERC20ABI, functionName: "mintOnce", args: [], }); // 2. Send transaction (automatically sponsored) await sendCallsAsync({ calls: [ { to: tokenAddress, data, }, ], }); }; return ( <Button onClick={() => handleMint("0x...")}> Mint Tokens </Button> );}How it Works
- Contract Interaction: We use
wagmi'suseSendCalls(or a wrapper hook) to send transactions. - Gas Sponsorship: The RISE Paymaster automatically sponsors eligible transactions.
- User Experience: The user signs the request with their Passkey (or Session Key if active), and the transaction is submitted instantly.
Sending a Transaction
To write to a contract, encode the function data using viem and send it using sendCallsAsync.
import { useSendCalls } from "wagmi";
import { encodeFunctionData } from "viem";
import { MintableERC20ABI } from "@/abi/erc20";
// ... inside your component
const { sendCallsAsync } = useSendCalls();
const handleMint = async () => {
const data = encodeFunctionData({
abi: MintableERC20ABI,
functionName: "mintOnce",
args: [],
});
await sendCallsAsync({
calls: [
{
to: "0x...", // Token Contract Address
data,
},
],
});
};