thorn-aa-sdk
v1.0.26
Published
Thorn Account Abstraction SDK
Downloads
189
Readme
Thorn Account Abstraction SDK
This package is only for Thorn-protocol testnet
Installation
npm i thorn-aa-sdk
Quickstart
import { SmartAccountClient } from "thorn-aa-sdk";
const userSA = await SmartAccountClient.create(signer);
const result = await userSA.buildUserOpSignAndSend([tx]);
const { receipt, success } = result.wait();
Usages
Get Smart Account address
const address = await userSA.getAddress();
Check if user already has Account Abstraction
await userSA.isAccountDeployed();
Deploy Smart Account if it not deploy
in here, we need a third wallet to send a transaction to deploy wallet
await tx = await userSA.deploy();
this function return a UnsignedTransaction, need signed and send to create wallet
Get Balance tokens of Smart Account
const balances = userSA.getBalance(["0x6718660522aAa470eb6EbcC461d505f518686Dc5", "0x8ab7B0c47f07E19C86E35Ebb44453cB266d1E79c"]);
//result form :
/*
[
{
address: '0x6718660522aAa470eb6EbcC461d505f518686Dc5',
name: 'TST',
symbol: 'MockToken',
decimals: 6,
balance: 0
},
{
address: '0x8ab7B0c47f07E19C86E35Ebb44453cB266d1E79c',
name: 'MockWrappedNative',
symbol: 'wNATIVE',
decimals: 18,
balance: 0
}
]
*/
Create transaction and send transaction
To send a transaction as a Smart Account, we need to build UnsignedTransactions corresponding to the execution commands, then use the sdk to interact, the sdk synthesizes the transactions into 1 UserOp, signs them and sends them to the bundler. to execute.
const erc20Interface = new Contract(addressContract, erc20Abi, provider);
const tx = await erc20Interface.getFunction("transfer").populateTransaction(addressInput, parseUnits(amountInput, 6));
const result = await userSA.buildUserOpSignAndSend([tx1, tx2, tx3]);
const { receipt, success } = await result.wait();
To create UnsignedTransactions, you can learn more about populateTransaction, the tx input needs at least 3 fields to, value, data.
Send transaction with token paymaster
If you want your transaction to be paid in Erc-20 coins instead of ROSE, add the parameter address token
const result = await userSA.buildUserOpSignAndSend([tx], tokenAddress);
const { receipt, success } = result.wait();
Paymaster
//Create object
import { UserTokenPaymaster } from "thorn-aa-sdk";
const paymaster = new UserTokenPaymaster();
// Get List token paymaster support
const listTokenSupport = await paymaster.getListTokenSupport();
// Get list token user approved
const listTokenUserApproved = await paymaster.getListTokenUserApproved(address);