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:
- Create a new app on the dashboard and copy the Paymaster RPC URL into your
.envfile. - Optionally, set up a Private Gas Policy on the dashboard and copy its sponsorship policy ID into your
.envfile.
If you would like to see a full example, you can reference it here.
- index.ts
- .env
import {
Erc7677Paymaster,
} from "abstractionkit";
const paymasterRPC = process.env.PAYMASTER_URL as string;
const paymaster: Erc7677Paymaster = new Erc7677Paymaster(paymasterRPC);
const sponsorshipPolicyId = process.env.SPONSORSHIP_POLICY_ID;
// userOperation and bundlerUrl should be defined elsewhere in your code
let paymasterUserOperation;
try {
// Sponsor gas using public gas policies
({ userOperation: paymasterUserOperation } =
await paymaster.createPaymasterUserOperation(
smartAccount,
userOperation,
bundlerUrl,
));
} catch (publicGasPolicyUnavailable) {
try {
// Sponsor gas using a private gas policy
({ userOperation: paymasterUserOperation } =
await paymaster.createPaymasterUserOperation(
smartAccount,
userOperation,
bundlerUrl,
sponsorshipPolicyId ? { sponsorshipPolicyId, policyId: sponsorshipPolicyId } : {},
));
} catch (privateGasPolicyUnavailable) {
// Fallback: propose ERC-20 token gas or native-token gas.
throw privateGasPolicyUnavailable;
}
}
userOperation = paymasterUserOperation;
PAYMASTER_URL=https://api.candide.dev/public/v3/11155111
SPONSORSHIP_POLICY_ID=