Developers Forum for XinFin XDC Network

Cover image for 📢Account Abstraction is LIVE on the XDC Mainnet with Etherspot
Alexandra
Alexandra

Posted on

📢Account Abstraction is LIVE on the XDC Mainnet with Etherspot

We’re excited to announce that Etherspot’s Account Abstraction Infrastructure is now available on the XDC Network mainnet, empowering developers to offer unparalleled user experiences!

With Etherspot’s Account Abstraction infrastructure, developers on the XDC Network will gain access to a suite of tools such as Etherspot Modular SDK, Skandha Bundler, and Arka Paymaster that streamline user interactions with their dApps. This integration is set to unlock a host of powerful features that will enhance both the developer and user experience on XDC:

  • Simplified Onboarding: Users can log into dApps effortlessly using familiar Web2 options like X (formerly Twitter), Discord, Gmail, and more, which makes onboarding in the Web3 space much easier.
  • Gas Fees in Stablecoins: Users can cover gas fees using stablecoins instead of native tokens, offering more flexibility and simplifying the transaction process.
  • Transaction Batching: Users can save time and reduce costs by combining multiple transactions into one, streamlining interactions and enhancing efficiency.
  • Smooth Cross-Chain Interactions: Etherspot’s AA infrastructure enables smoother interactions across different chains within a single dApp, breaking down barriers and creating a more unified user experience.

⚙️ To implement powerful Account Abstraction features into your dApp, follow these steps:

1.Install the packages

❗️ Note: You should have installed Node.js (version 18.10.0 or higher).

Install Etherspot Modular SDK with this command

npm i @etherspot/modular-sdk --save
Enter fullscreen mode Exit fullscreen mode

2.Import the SDK

import { ModularSdk } from '@etherspot/modular-sdk';
Enter fullscreen mode Exit fullscreen mode

3.Get the smart contract address

If you’re unsure about the difference between key-based accounts and smart contract accounts, please take a look at this page.

In this example, we simply create a key-based wallet with ethers.js like so:

const randomWallet = ethers.Wallet.createRandom();
const privateKey = randomWallet.privateKey;
Enter fullscreen mode Exit fullscreen mode
Set the privayeKey in the .env : WALLET_PRIVATE_KEY
set the apiKey in .env: API_KEY
Enter fullscreen mode Exit fullscreen mode

Then we use this key-based wallet to instantiate the SDK on XDC Network and get the wallet address.

const chainId = 50;
const modularSdk = new ModularSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, 
{ chainId: chainId, 
bundlerProvider: new EtherspotBundler(chainId, 
bundlerApiKey, customBundlerUrl) }) 
const address: string = await primeSdk.getCounterFactualAddress();
console.log(address);
Enter fullscreen mode Exit fullscreen mode

4.Send funds to another address

Getting all together into a function

import { EtherspotBundler, ModularSdk, MODULE_TYPE, printOp, sleep } from '@etherspot/modular-sdk';
import * as dotenv from 'dotenv';

const recipient = ''; // recipient wallet address
const value = '0.0000001'; // transfer value
const bundlerApiKey = process.env.API_KEY;
const privateKey = process.env.WALLET_PRIVATE_KEY;

// initializating sdk...
const modularSdk = new ModularSdk({ privateKey: process.env.WALLET_PRIVATE_KEY },
{ chainId: Number(process.env.CHAIN_ID),
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) })

console.log('address: ', modularSdk.state.EOAAddress)

// get address of EtherspotWallet...
const address: string = await modularSdk.getCounterFactualAddress();
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`);

// clear the transaction batch
await modularSdk.clearUserOpsFromBatch();

// add transactions to the batch
const transactionBatch = await modularSdk.addUserOpsToBatch({ to: recipient, value: ethers.utils.parseEther(value) });
console.log('transactions: ', transactionBatch);

// get balance of the account address
const balance = await modularSdk.getNativeBalance();

console.log('balances: ', balance);

// estimate transactions added to the batch and get the fee data for the UserOp
const op = await modularSdk.estimate();
console.log(`Estimate UserOp: ${await printOp(op)}`);

// sign the UserOp and sending to the bundler...
const uoHash = await modularSdk.send(op);
console.log(`UserOpHash: ${uoHash}`);

// get transaction hash...
console.log('Waiting for transaction...');
let userOpsReceipt = null;
const timeout = Date.now() + 60000; // 1 minute timeout
while ((userOpsReceipt == null) && (Date.now() < timeout)) {
await sleep(2);
userOpsReceipt = await modularSdk.getUserOpReceipt(uoHash);
}
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
Enter fullscreen mode Exit fullscreen mode

Next steps

For the next steps, you can look at functions or examples to tailor the dApp to what you’re trying to accomplish.

For more info and guidance on commencing your development journey with Etherspot, please refer to our đź“šdocumentation here.

If you have any questions, do not hesitate to chat with the team on đź‘ľDiscord.

🧑‍💻Build unmatched Web3 user experience by removing usability pain points with Etherspot's Account Abstraction infrastructure! Happy coding!

Discussion (4)

Collapse
mrblockchain22 profile image
Salomon Morales

Excellent!! 🔥

Collapse
ram_gawas_721be0b970fbc4f profile image
ram gawas

I already implement AA testnet setup in my project and its working, give easy way to convert to mainnet.

Collapse
ram_gawas_721be0b970fbc4f profile image
ram gawas

Thank you

Collapse
0xbeny profile image
Beny

Fascinated about this integration.
Let's build a community around it to start utilizing it.