Once you have connected your EOA signer and created an instance of Smart Account, the address is the public property and remains the same across all EVM chains.
// AA addressconstaddress=awaitsmartAccount.getAddress();// EOA addressconstaddress=awaitsmartAccount.getOwner();// load account more info.constaccountInfo=awaitsmartAccount.getAccount();
Get Fee Quotes
Before send transactions, you can get fee quotes and display on UI Modal, users can choose which token to use to pay gas fees.
consttx= { to:'0x...', value:'0x...', data:'0x...',}// or bacth transactionsconsttxs= [ { to:'0x...', value:'0x...', data:'0x...', }, { to:'0x...', value:'0x...', data:'0x...', }]//get fee quotes with tx or txsconstfeeQuotesResult=awaitsmartAccount.getFeeQuotes(tx);// gasless transaction userOp, maybe nullconstgaslessUserOp=feeQuotesResult.verifyingPaymasterGasless?.userOp;constgaslessUserOpHash=feeQuotesResult.verifyingPaymasterGasless?.userOpHash;// pay with Native tokens: transaction userOpconstpaidNativeUserOp=feeQuotesResult.verifyingPaymasterNative?.userOp;constpaidNativeUserOpHash=feeQuotesResult.verifyingPaymasterNative?.userOpHash;// pay with ERC-20 tokens: fee quotesconsttokenPaymasterAddress=feeQuotesResult.tokenPaymaster.tokenPaymasterAddress;consttokenFeeQuotes=feeQuotesResult.tokenPaymaster.feeQuotes;
Build User Operation
Builds a UserOp object from the provided array of Transactions. It also accepts optional feeQuote and tokenPaymasterAddress. Returns a Promise that resolves to the UserOpBundle.
// build user operation, feeQuote and tokenPaymasterAddress is optional.constuserOpBundle=awaitsmartAccount.buildUserOperation({ tx, feeQuote, tokenPaymasterAddress })constuserOp=userOpBundle.userOp;constuserOpHash=userOpBundle.userOpHash;
Send User Operation
Sends the pre-signed UserOperation to the Particle network for execution. Returns a Promise that resolves to a TransactionHash.
// Some codeconsttxHash=awaitsmartAccount.sendUserOperation({ userOp, userOpHash });
Wallet Deployment flow
Any gasless or user paid transaction will check whether the wallet is deployed or not. If the wallet is not deployed, the SDK will batch the wallet deployment with the intended transaction/batch transactions. This behaviour is handled within the SDK itself & would require no changes in your code to enable this.
Deploy Wallet Contract Manually
// check the constract is deployedconstisDeploy=awaitsmartAccount.isDeployed();if (!isDeploy) {consttxHash=awaitsmartAccount.deployWalletContract();}
Wrap Provider
If your app has implemented sending transactions, or use web3.js, you can wrap the EIP-1193 provider to quickly implement AA wallet.
import { AAWrapProvider, SendTransactionMode, SendTransactionEvent } from'@particle-network/aa';import Web3 from"web3";// sendTxMode: UserPaidNative(default), Gasless, UserSelectconstwrapProvider=newAAWrapProvider(smartAccount,SendTransactionMode.UserPaidNative);// replace any EIP-1193 provider to wrapProviderconstweb3=newWeb3(wrapProvider);//send user paid transactionawaitweb3.eth.sendTransaction(tx);// send gassless transactionconstwrapProvider=newAAWrapProvider(smartAccount,SendTransactionMode.Gasless);constweb3=newWeb3(wrapProvider);awaitweb3.eth.sendTransaction(tx);// use select pay gas token or gaslessconstwrapProvider=newAAWrapProvider(smartAccount,SendTransactionMode.UserSelect);constweb3=newWeb3(wrapProvider);wrapProvider.once(SendTransactionEvent.Request, (feeQuotesResult) => {// let the user select the pay gas ERC-20 tokenwrapProvider.resolveSendTransaction({ feeQuote:feeQuotesResult.tokenPaymaster.feeQuote[0], tokenPaymasterAddress:feeQuotesResult.tokenPaymaster.tokenPaymasterAddress });// or pay with native tokenwrapProvider.resolveSendTransaction(feeQuotesResult.verifyingPaymasterNative);// or send gaslessif (feeQuotesResult.verifyingPaymasterGasless) {wrapProvider.resolveSendTransaction(feeQuotesResult.verifyingPaymasterGasless); }// or reject send transactionwrapProvider.rejectSendTransaction({ message:'user rejected'});});awaitweb3.eth.sendTransaction(tx);