Skip to main content

Quickstart

In this guide, we will create a smart account and mint a Token with AbstraXn SDK.

1. Setup

Let's add AbstraXn packages:

npm install ethers@5.7 @abstraxn/account @abstraxn/bundler @abstraxn/common @abstraxn/core-types @abstraxn/modules

The Account package will help you with creating Smart Account and an interface with them to send transactions. The same package can be used to also import the paymaster and bundler.

2. Create a Smart Account

We will build a Smart Account, and its owner will be the Externally Owned Account (EOA) corresponding to the private key. Wallets like as MetaMask, TrustWallet, Coinbase Wallet, and so on can provide you with the private key.

import { Signer, ethers } from "ethers";
import { AbstraxnSmartAccount } from "@abstraxn/account";
import {
DEFAULT_ECDSA_OWNERSHIP_MODULE,
DEFAULT_ENTRYPOINT_ADDRESS,
ECDSAOwnershipValidationModule,
} from "@abstraxn/modules";
import { Bundler, IBundler } from "@abstraxn/bundler";
import { ChainId } from "@abstraxn/core-types";

// Create a new Web3Provider using the 'ethereum' object
const provider = new ethers.providers.Web3Provider(ethereum);

// create instance of bundlers
const bundler: IBundler = new Bundler({
bundlerUrl: "",
chainId: ChainId.POLYGON_AMOY, // you can use multiple chains available in chainId object
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
});

// instance of ownership module
const ownerShipModule = await ECDSAOwnershipValidationModule.create({
signer: provider.getSigner() as Signer, // ethers signer object
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE,
});

// Note that bundler is optional. You can choose to create new instances of this later and make account API use
const abstraxnSmartAccount = await AbstraxnSmartAccount.create({
chainId: ChainId.POLYGON_AMOY, // you can use multiple chains available in chainId object
activeValidationModule: ownerShipModule,
defaultValidationModule: ownerShipModule,
bundler: bundler, // instance of bundler
});

// you can get your smart account wallet address by getAccountAddress()
const address = await abstraxnSmartAccount.getAccountAddress();

//Contract instance
const contract = new ethers.Contract(
contractAddress,
Contract_ABI, // contract abi
provider
);

//contract function
const mint = await contract.populateTransaction.mint(
walletAddress,
amount
);

//transaction
const tx1 = {
to: contractAddress,
data: mint.data,
};

// you can create your userOp by buildUserOp()
const userOp = await abstraxnSmartAccount.buildUserOp([tx1, ...], {
overrides: {
...
}
});

// you can send your userOp to bundler by sendUserOp()
const userOpResponse = await abstraxnSmartAccount.sendUserOp(userOp);

//wait for response
const { receipt } = await userOpResponse.waitForTxHash();

//your transaction receipt
console.log(receipt)
  1. We create a transaction object.
  2. We send the transaction to our bundler.
  3. We store the response in a variable called userOpResponse.
  4. We retrieve the transaction detail by calling userOpResponse.waitForTxHash().

To wait for a specific number of network confirmations before getting the value, use wait() with a number argument. For instance, transactionResponse.wait(5) waits for 5 confirmations before returning the value.

Check out the transaction details in your console! You just created and executed your first userOps using the AbstraXn SDK.

If you run into any errors, check out troubleshooting for common errors.

🎉 Congratulations on completing the quickstart!

Check out Tutorials

Explore the tutorials for various use cases.

Send a batch of transactions

In this you will do batching of transactions which is sending more than one transaction in an array and execute them with a single signature.

To dive deeper, check out more use cases.