Account Abstraction simplifies blockchain interactions by allowing smart contracts to serve as user accounts, merging contract capabilities with account management. The Titan upgrade opens the door for Account Abstraction to become reality on Cronos Testnet.
Account Abstraction opens up possibilities for numerous use cases such as multi-signature transactions, social recovery, contract whitelisting, custom gas tokens, subsidizing gas fees, and much more. It expands the use-case potential of DApps and enables a more intuitive user experience.
Key components have been developed to facilitate the development of Account Abstraction. Note that some of these components are still at an experimental stage:
User Operations, serve as a new type of transaction object containing additional data, allows for custom transaction and security configurations.
JSON-RPC API debug_traceCall, allows for the simulation of User Operations before their actual execution on the chain.
Bundlers serve as crucial nodes that bundle unsigned User Operations into a single package for signing and subsequent publication on the mainnet. Bundlers estimate transaction fees.
Entry Point Contract, an audited and trusted singleton contract, is functional and can process the execution and validating User Operations.
Native account abstraction is still at an experimental stage on Cronos, not yet suitable for production use case. However, there are application-level account abstraction solutions available for developers who need AA functionality now, such as Cometh. Please contact Cronos Labs if you would like to be introduced to the relevant developer tool platforms.
Send a UserOperation using userop.js
In this guide, we will go through how to send a userop transaction with subsidized gas fee.
Here we are using userop.js to send UserOperations but you can use any library you like, even using curl
We will create a new project for sending transactions
import { ethers,Wallet,Contract } from"ethers";import { Presets,Client } from"userop";import { config } from"dotenv";config();constNODE_RPC_URL=process.env.NODE_RPC_URL;constBUNDLER_RPC_URL=process.env.BUNDLER_RPC_URL;constSIGNER_PKEY=process.env.SIGNER_PKEY;constENTRY_POINTS=process.env.ENTRY_POINTS;constACCOUNT_FACTORY=process.env.ACCOUNT_FACTORY;asyncfunctionmain() {// signer is the owner of the smart accountconstsigner=newethers.Wallet(SIGNER_PKEY)// Initialize userop buildervar builder =awaitPresets.Builder.SimpleAccount.init( signer,NODE_RPC_URL, { overrideBundlerRpc:BUNDLER_RPC_URL, entryPoint:ENTRY_POINTS, factory:ACCOUNT_FACTORY, } );// these two addresses are different// need to fund the smart account before running this scriptconsole.log(`Signer address: ${signer.address}`);console.log(`Account address: ${builder.getSender()}`);// build a tranfer transaction builder = builder.execute("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","100",ethers.utils.hexlify("0x") )// create the clientconstclient=awaitClient.init(NODE_RPC_URL, { overrideBundlerRpc:BUNDLER_RPC_URL, entryPoint:ENTRY_POINTS, factory:ACCOUNT_FACTORY, } );// send the useroperation to the bundler nodeconstres=awaitclient.sendUserOperation(builder, {onBuild: (op) => {console.log("Signed UserOperation:",op); }, });console.log(`UserOpHash: ${res.userOpHash}`);// !!! this step can get stuck in a local geth dev setup// because the bundler node is waiting for new block event to bundle the userops// try to send a new tx in the local geth dev setup to trigger bundleconsole.log("Waiting for transaction...");constev=awaitres.wait();console.log(`Transaction hash: ${ev?.transactionHash ??null}`);}main().then();
If successful, you will see the above logs including transaction hash and userOpHash printed out.
We can now verify with this tx hash on the block explorer, that we have successfully sent out a TX, and the gas fees were funded by the account address 0x6813Eb9362372EE...19671cBA69.