@thangnn91/paymaster-helper-v6
v0.0.9
Published
Paymaster helper ethers-v6
Downloads
4
Readme
Paymaster Helper
A paymaster is a smart contract that can pay for transactions for its users, executing any logic to decide whether it should forward a transaction. For example, developers can allow users to run transactions for free or pay in your application's ERC-20 token instead. The library helps developers easily interact with paymaster contracts
🛠 Prerequisites
node: >= 18.0.0
(installation guide)ethers: ~5.7.0
zksync-web3: ~0.14.4
📥 Installation & Setup
Using npm package manager
npm i @thangnn91/paymaster-helper-v6
Using yarn
yarn add @thangnn91/paymaster-helper-v6
📝 Examples
Types
interface BaseProps {
network: "testnet" | "mainnet";
paymasterAddress?: string;
populateTransaction: ethers.ContractTransaction;
innerInput?: string;
}
interface WalletExecuteProps extends BaseProps {
signer: string | Wallet;
paymentToken?: string;
nftType?: 0 | 1 | 2 | 3;
}
interface SignerExecuteProps extends BaseProps {
signer?: Signer;
paymentToken?: string;
nftType?: 0 | 1 | 2 | 3;
}
//output data is used to execute outside
export type BuilderOutput = {
populatedTx: ethers.PopulatedTransaction;
gasLimit: BigNumber;
gasPrice: BigNumber;
};
Using by wallet/private key
import { WalletPaymaster, SignerPaymaster } from "@holdstation/paymaster-helper"
const contract = new Contract(CONTRACT_ADDRESS, CONTRACT_ABI, provider)
const populateContract = await contract.populateTransaction[method](...params, {
from: ACCOUNT,
});
//execute by wallet
await WalletPaymaster.paymasterExecute({
network: "testnet",
signer: signer,
paymentToken: PAYMENT_TOKEN,
populateTransaction: populateContract
})
//execute using private key
await WalletPaymaster.paymasterExecute({
network: "testnet",
signer: PRIVATE_KEY,
paymentToken: PAYMENT_TOKEN,
populateTransaction: populateContract
})
Using by Web3Provider Signer (client extension)
function walletClientToSigner(walletClient: WalletClient) {
const { account, chain, transport } = walletClient;
const network = {
chainId: chain.id,
name: chain.name,
ensAddress: chain.contracts?.ensRegistry?.address,
};
const provider = new Web3Provider(transport, network);
const signer = provider.getSigner(account.address);
return signer;
}
const walletConnectSigner = walletClientToSigner(walletClient);
await SignerPaymaster.paymasterExecute({
//If no signer is specified, we will obtain it from the extension.
signer: walletConnectSigner,
network: "testnet",
paymentToken: PAYMENT_TOKEN,
populateTransaction: populateContract
})