How to Send a Gasless Transaction | EIP-7702
Smart EOAs via EIP-7702
EIP-7702 allows regular Ethereum EOAs (Externally Owned Accounts) to act as smart accounts for a transaction. This enables features like gas sponsorship, multisig, and more, without permanently converting the EOA.
With EIP-7702, users can benefit from gasless transactions by leveraging publicly available gas policies set up by third parties on InstaGas—like PoolTogether, Revoke, AAVE, and many more. If no matching public gas policy is found for the user operation, you can fall back to a private gas policy of your own.
Definitions:
- Public Gas Policies: Gas sponsorships provided by Dapps and do not require a sponsorship policy ID.
- Private Gas Policies: Require a sponsorship policy ID and can be used by the wallet if 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
.env
file. - 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.
- index.ts
- .env
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;
PAYMASTER_RPC=https://api.candide.dev/public/v3/sepolia
SPONSORSHIP_POLICY_ID=