Skip to content

Wallet actions

After initializing OpenfortProvider and creating an embedded wallet, you can submit smart-account calls from React Native using the wallet_sendCalls method. The Expo-based recipes in @recipes-hub/usdc and @recipes-hub/hyperliquid show full flows that combine transfers with on-chain reads. The helper below focuses on a simple ERC-20 transfer.

Send an ERC-20 transfer

useSendUsdc.ts
import { useMemo } from 'react';
import { encodeFunctionData, parseUnits } from 'viem';
import { useWallets } from '@openfort/react-native';
 
const usdcAddress = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'; // replace with your token
const usdcAbi = [{
  name: 'transfer',
  type: 'function',
  stateMutability: 'nonpayable',
  inputs: [
    { name: 'to', type: 'address' },
    { name: 'amount', type: 'uint256' },
  ],
  outputs: [{ name: 'success', type: 'bool' }],
}];
 
export function useSendUsdc(chainIdHex = '0xaa36a7') {
  const { activeWallet } = useWallets();
 
  return useMemo(() => {
    if (!activeWallet) return null;
 
    return async (to: `0x${string}`, amount: string) => {
      const provider = await activeWallet.getProvider();
      const units = parseUnits(amount, 6);
      const data = encodeFunctionData({ abi: usdcAbi, functionName: 'transfer', args: [to, units] });
 
      return await provider.request({
        method: 'wallet_sendCalls',
        params: [{
          version: '1.0',
          chainId: chainIdHex,
          from: activeWallet.address,
          calls: [{ to: usdcAddress, value: '0x0', data }],
        }],
      });
    };
  }, [activeWallet, chainIdHex]);
}

Invoke this function from a button handler or mutation. To build richer experiences (polling balances, orchestrating multi-call flows) follow the patterns in the recipes referenced above.

Sponsor gas from the dashboard

Gas sponsorship keeps those actions ETH-free for users—or lets you collect ERC-20 reimbursements—by leveraging dashboard policies.

  1. Open Dashboard → Sponsor policies, create a policy, and copy the generated pol_... identifier.
  2. Restrict eligibility by chain and method (for example wallet_sendCalls on Base Sepolia).
  3. Pick Pay gas for user to sponsor calls or Charge dynamic/fixed amount of ERC-20 to charge users before calls are sent.

Attach the policy directly in walletConfig so the React Native SDK applies it to every bundle.

app/_layout.tsx
<OpenfortProvider
  publishableKey="YOUR_PROJECT_PUBLISHABLE_KEY"
  walletConfig={{
    shieldPublishableKey: "YOUR_SHIELD_PUBLISHABLE_KEY",
    getEncryptionSession: async () => "<SESSION_ID>",
    ethereumProviderPolicyId: {
      [84532 /* Base Sepolia */]: 'pol_...',
    },
  }}
>
  <Slot />
</OpenfortProvider>

Policy changes go live immediately; any subsequent wallet_sendCalls requests inherit the latest sponsorship configuration.

More examples

  • MainAppScreen.tsx – drives gas-sponsored USDC transfers between embedded wallets.
  • UserScreen.tsx – combines transfers with third-party API calls in a mobile trading UI.