SDK For Smarter Wallet Frond End
MPC key management and build ERC4337 transaction
Features
- MPC key management
- Build AA transaction
Installation
To install the package, run the following command:
npm install sw-fe-sdk
Usage
Before using the package, make sure to import the required modules and configure the necessary variables:
import { MPCManageAccount } from 'sw-fe-sdk';
import { JSONBigInt } from 'sw-fe-sdk';
Configuration
Set up the RPC URL and other constants:
const rpcUrl = "https://mumbai-rpc.web3idea.xyz";
Creating an MPC Account
To initialize and use an MPC account, follow these steps:
- Initialize the account with the given key string:
const mpcAccount = new MPCManageAccount(
rpcUrl,
mpcBackendApiUrl,
mpcWasmUrl,
walletFactoryAddres,
authorization,
createWalletApiUrl
);
await mpcAccount.initAccount(mpcKeyStr);
- Calculate the owner address:
const ownerAddress = await mpcAccount.getOwnerAddress();
console.log("Owner Address:", ownerAddress);
Transactions
Transfer Native Token with token pay master
To build a transaction for transferring native tokens:
const gasPrice = await ethersWallet.getGasPrice();
const op = await mpcAccount.buildTxTransferNativeToken(
entryPointAddress,
gasPrice,
"0xRecipientAddress",
ethers.utils.parseEther("Amount"),
tokenPaymasterAddress,
payGasFeeTokenAddress
);
console.log("Transfer native token tx op:", JSONBigInt.stringify(op));
Transfer Native Token without token pay master
TODO
Transfer ERC20 Token with token pay master
To build a transaction for transferring ERC20 tokens:
const gasPrice = await ethersWallet.getGasPrice();
const op = await mpcAccount.buildTxTransferERC20Token(
entryPointAddress,
gasPrice,
"0xRecipientAddress",
ethers.utils.parseEther("Amount"),
"0xTokenAddress",
tokenPaymasterAddress,
payGasFeeTokenAddress
);
console.log("Transfer ERC20 token tx op:", JSONBigInt.stringify(op));
Transfer ERC20 Token without token pay master
TODO