Quick Start Guide

This guide will help you set up your environment and perform your first transaction using 0xGassless.

Setting Up Your Environment

Step 1: Install the SDKs

First, ensure you have installed the 0xGassless SDK:

npm install @0xgasless/smart-account

Step 2: Configure the Bundler and Paymaster

Replace {chainId} with your actual chain ID:

  • Bundler URL:

    https://bundler.0xgasless.com/{chainId}
  • Paymaster URL:

    https://paymaster.0xgasless.com/v1/{chainId}/rpc

Step 3: Initialize the SDK

Here's an example of how to initialize the SDK with your configuration:

import {
  PaymasterMode,
  createBundler,
  createSmartAccountClient,
} from "@0xgasless/smart-account";
import { ethers } from "ethers"; //ethers@5.7.2

const chainId = 8453
const bundlerUrl = `https://bundler.0xgasless.com/${chainId}`; // Replace '1' with your chainId
const paymasterUrl = `https://paymaster.0xgasless.com/v1/${chainId}/rpc`; // Replace '1' with your chainId

const rpc = ""
const privateKey = ""
const provider = new ethers.providers.JsonRpcProvider(rpc);
const wallet = new ethers.Wallet(privateKey, provider);

const smartWallet = 
await createSmartAccountClient({
  signer: wallet!,
  paymasterUrl: PaymasterUrl,
  bundlerUrl: bundlerUrl,
  chainId: chainId,
});
// Initialize and use your smart account as needed

First Transaction

Once your environment is set up, you can execute your first gasless transaction.

Step 1: Create a Transaction

Create a transaction object with the necessary details:

const transaction = {
  to: '0xRecipientAddress', // Replace with the recipient's address
  value: '1000000000000000000', // Amount in wei (1 ETH in this example)
  data: '0x', // Optional data payload
};

Step 2: Send the Transaction

Use the smartAccount object to send the transaction:


const userOpResponse = await smartWallet.sendTransaction(transaction, {
	paymasterServiceData: { mode: PaymasterMode.SPONSORED },
});

console.log("UserOp Response", userOpResponse);

const userOpReceipt = await userOpResponse.wait();
if (userOpReceipt.success == "true") {
	console.log("UserOp receipt", userOpReceipt);
	console.log("Transaction receipt", userOpReceipt.receipt);
}

Step 3: Monitor the Transaction

Monitor the transaction status:

smartAccount.provider.on('transactionHash', (hash) => {
  console.log('Transaction hash:', hash);
});

smartAccount.provider.on('receipt', (receipt) => {
  console.log('Transaction receipt:', receipt);
});

smartAccount.provider.on('error', (error) => {
  console.error('Transaction error:', error);
});

By following these steps, you should be able to set up your environment and execute your first gasless transaction using 0xGassless. For more detailed usage and advanced features, refer to the other sections of this documentation.

Last updated