Package Exports
- core-paymastersdk
- core-paymastersdk/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (core-paymastersdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Core Paymaster SDK
An SDK for interacting with the Core Paymaster contract on Core Testnet (Chain ID 1114). This SDK simplifies the process of managing and using a paymaster contract for ERC-4337 Account Abstraction.
Features
- Manage paymaster whitelist and gas limits
- Deposit funds to the paymaster
- Withdraw funds from the paymaster
- Attach the paymaster to user operations
- Monitor paymaster events
- Interact with bundlers to send user operations
Installation
npm install core-paymaster-sdkQuick Start
import { ethers } from "ethers";
import { createPaymasterClient, createBundlerClient } from "core-paymaster-sdk";
// Create a provider for Core Testnet
const provider = new ethers.providers.JsonRpcProvider(
"https://rpc.test.btcs.network"
);
// Create a wallet for signing transactions
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
// Create the paymaster client
const paymasterClient = createPaymasterClient(wallet);
// Check paymaster balance
const balance = await paymasterClient.getBalance();
console.log(`Paymaster balance: ${ethers.utils.formatEther(balance)} ETH`);
// Whitelist a smart contract account
const tx = await paymasterClient.setWhitelistedAccount(
"0xYourSmartContractAddress",
true
);
await tx.wait();
// Set a gas limit for the account
await paymasterClient.setAccountGasLimit(
"0xYourSmartContractAddress",
ethers.utils.parseEther("0.01") // 0.01 ETH gas limit
);
// Listen for gas payment events
paymasterClient.on("GasPaymentMade", (account, gasAmount) => {
console.log(
`Gas payment made for ${account}: ${ethers.utils.formatEther(
gasAmount
)} ETH`
);
});Using with a Bundler
import { ethers } from "ethers";
import { createBundlerClient } from "core-paymaster-sdk";
// Create a bundler client (replace with your preferred bundler URL)
const bundlerClient = createBundlerClient("https://your-bundler-url");
// Send a user operation via the bundler
const userOp = {
sender: "0xYourSmartContractAddress",
nonce: "0x01",
callData: "0xcallDataHex",
// Other userOp fields...
paymasterAndData: "0x9A5e0F8D2153c8391b098FfCB2404149D7e0b402", // The paymaster address
};
// Send the operation
const userOpHash = await bundlerClient.sendUserOperation(userOp);
console.log(`UserOperation hash: ${userOpHash}`);
// Monitor the status
const status = await bundlerClient.getUserOperationStatus(userOpHash);
console.log(`Status: ${status.state}`);Advanced Usage
See the examples directory for more advanced usage patterns.
Configuration
The SDK can be customized with various configuration options:
// Custom configuration
const paymasterClient = createPaymasterClient(wallet, {
paymasterAddress: "0xCustomPaymasterAddress",
entryPointAddress: "0xCustomEntryPointAddress",
chainId: 1114, // Core Testnet
});API Reference
PaymasterClient
A client for interacting with the paymaster contract.
Methods
deposit(amount)- Deposit funds to the paymasterwithdraw(amount)- Withdraw funds from the paymastergetBalance()- Get the current balance of the paymasterisEnabled()- Check if the paymaster is enabledsetEnabled(enabled)- Enable or disable the paymastersetWhitelistedAccount(account, whitelisted)- Add or remove an account from the whitelistsetAccountGasLimit(account, gasLimit)- Set a gas limit for an accountbatchSetWhitelistedAccounts(accounts, whitelisted)- Batch whitelist multiple accountsresetAccountGasUsed(account)- Reset the gas usage counter for an accountisAccountWhitelisted(account)- Check if an account is whitelistedgetAccountGasLimit(account)- Get account gas limitgetAccountGasUsed(account)- Get account gas usedgetAccountGasDetails(account)- Get all gas details for an accounton(event, callback)- Add an event listeneroff(event, callback)- Remove an event listenerattachToUserOperation(userOp, extraData)- Attach the paymaster to a user operation
BundlerClient
A client for interacting with ERC-4337 bundlers.
Methods
sendUserOperation(userOp)- Send a user operation to the bundlergetUserOperationStatus(userOpHash)- Get the status of a user operationestimateUserOperationGas(userOp)- Estimate gas for a user operationgetSupportedEntryPoints()- Get the supported entry points by the bundlerisEntryPointSupported(entryPointAddress)- Check if the bundler supports a specific entry point
License
MIT