Skip to main content

How to Send a Gasless Transaction | EIP-7702

Smart EOAs via EIP-7702

EIP-7702 enables Ethereum EOAs (Externally Owned Accounts) to function as smart accounts for transactions, unlocking features like gas sponsorship and multisig without permanently converting the EOA.

With EIP-7702, users access gasless transactions through publicly available gas policies on InstaGas from third parties like PoolTogether, Revoke, and AAVE. If no matching public gas policy is found, fall back to your private gas policy.

Definitions:

  • Public Gas Policies: Gas sponsorships provided by dApps that don't require a sponsorship policy ID
  • Private Gas Policies: Require a sponsorship policy ID and serve as fallback when no public gas policy matches the user operation

Steps to Implement Gasless Transactions:

  1. Create a new app on the dashboard and copy the Paymaster RPC URL into your .env file.
  2. Optionally, set up a Private Gas Policy on the dashboard and copy its sponsorship policy ID into your .env file.

If you would like to see a full example, you can reference it here.

import {
CandidePaymaster,
} from "abstractionkit";

const paymasterRPC = process.env.PAYMASTER_RPC as string;
const paymaster: CandidePaymaster = new CandidePaymaster(paymasterRPC);
const sponsorshipPolicyId = process.env.SPONSORSHIP_POLICY_ID;

// userOperation and bundlerUrl should be defined elsewhere in your code
let paymasterUserOperation;
let sponsorMetadata;
try {
// Sponsor gas using public gas policies
[paymasterUserOperation, sponsorMetadata] =
await paymaster.createSponsorPaymasterUserOperation(
userOperation,
bundlerUrl,
);
} catch (publicGasPolicyUnavailable) {
try {
// Sponsor gas using a private gas policy
[paymasterUserOperation, sponsorMetadata] =
await paymaster.createSponsorPaymasterUserOperation(
userOperation,
bundlerUrl,
sponsorshipPolicyId,
);
} catch (privateGasPolicyUnavailable) {
// Fallback: propose to the user the option to pay gas in ERC-20 tokens
} catch (erc20GasPaymentUnavailable) {
// Last fallback: propose to the user the option to pay gas in the native token
}
}

userOperation = paymasterUserOperation;