Arcana Gasless (Standalone) SDK Usage
Estimated time to read: 2 minutes
Use the Arcana Gasless (Standalone) SDK to enable gasless transactions in third-party browser-based wallets. Gasless transactions are a built-in feature of the Arcana wallet and don't require installation of the Arcana Gasless (Standalone) SDK.
Installation
npm i @arcana/scw
Usage
Initialize
During initialization, the gasless SDK creates an SCW account associated with the EoA account corresponding to the provider window.ethereum
.
const scw = new arcana.scw.SCW();
await scw.init("<app_id>", window.ethereum, "<gateway_url>");
Perform Gasless Transaction
const erc20abi = [...];
let amount = 0.1;
const erc20Address = "0xfDB2aA382866bb31704558a0c439dA91353651a9";
const toAddress = "0xA9E78cef5e6c0081b68AdA2554c04198DfF17C69";
const Erc20Interface = new ethers.utils.Interface(erc20abi);
const encodedData = Erc20Interface.encodeFunctionData("transfer", [
toAddress,
ethers.utils.parseEther(amount + ""),
]);
// You need to create transaction objects of the following interface
const tx1 = {
from: scw.getSCWAddress(),
to: erc20Address, // destination smart contract address
data: encodedData,
};
let tx = await scw.doTx(tx1);
await tx.wait();
console.log(`Transfer done ${tx.userOpHash}`)
Functions
getSCWAddress()
Returns the Smart Address as per ERC-4337, the SCW address, associated with the current user's EoA address.
getPaymasterBalance()
Returns the balance available in the gas tank that can be utilized via the current user's SCW address.
doTx()
Takes the transaction object as input and performs the gasless transaction using the SCW address. If the gas tank is depleted or not available, then the gas fees are paid via the SCW account. In this case when the gas tank is not available, if the SCW account has the necessary funds for gas fees, the transaction goes through otherwise it fails.