Build and deploy a paymaster smart contract that can sponsor the gas fees of transactions for other accounts on Abstract.
-
Get a copy of the
paymastersexample directory from the Abstract Examples repository:mkdir -p paymasters && curl -L https://codeload.github.com/Abstract-Foundation/examples/tar.gz/main | tar -xz --strip=2 -C paymasters examples-main/paymasters && cd paymasters
-
Install dependencies.
yarn
-
Use Hardhat to run
yarn compileand compile theMyPaymastersmart contract.
To demo the code, deploy and submit a gas-sponsored transaction from a wallet:
-
Compiling the contracts.
yarn compile
-
Create a new Hardhat configuration variable for your wallet private key.
When prompted, enter the private key of the wallet you want to use to deploy the contract. It is strongly recommended to use a new wallet for this purpose.
npx hardhat vars set WALLET_PRIVATE_KEY -
Deploy the
MyPaymastercontract.The
defaultNetworkinside hardhat.config.ts is set toabstractTestnet. You will need testnet ETH from a faucet in your wallet to deploy the contract to Abstract.yarn deploy
-
Take the outputted
Contract addressand paste it on line11of the interact.ts file:const CONTRACT_ADDRESS = "<your-deployed-contract-address-here>";
-
Interact with the deployed contract.
yarn interact
This will submit a transaction to the network that your paymaster will sponsor the gas fees for.
-
Install the ZKsync CLI
yarn global add zksync-cli
-
For local development, ensure Docker is installed and running.
docker --version docker info
-
For local development, run an "In Memory node".
zksync-cli dev start
-
Set the hardhat default network to
inMemoryNodein hardhat.config.ts.defaultNetwork: "inMemoryNode",
-
Use the
RICH_WALLETSarray available in the utils.ts file to access accounts loaded with funds on the local node.