Functions and Methods

This document provides a detailed overview of the primary functions and methods available in the 0xGassless SDK. These functions enable developers to interact with the 0xGassless platform to manage gasless transactions, configure modules, and more.

initialize

Initializes the 0xGassless SDK with the provided configuration.

Parameters

  • config (Object): Configuration object containing necessary parameters.

    • network (String): The blockchain network to use (e.g., base, ropsten).

    • rpcUrl (String): The RPC URL for connecting to the blockchain.

    • bundlerUrl (String): The URL of the 0xGassless bundler service.

      "bundlerUrl": "https://bundler.0xgassless.com/{chainId}"
    • paymasterUrl (String): The URL of the 0xGassless Paymaster service.

      "PaymasterUrl": "https://paymaster.0xgassless.com/v1/{chainId}/rpc"
    • privateKey (String): The private key of the account to use for signing transactions.

Example

const config = {
  network: "base",
  rpcUrl: "https://base.infura.io/v3/YOUR_INFURA_PROJECT_ID",
  bundlerUrl: "https://bundler.0xgassless.com/1",
  paymasterUrl: "https://paymaster.0xgassless.com/v1/1/rpc",
  privateKey: "0xYourPrivateKey"
};

const gassless = initialize(config);
console.log("0xGassless SDK initialized.");

sendTransaction

Sends a gasless transaction through the 0xGassless network.

Parameters

  • transaction (Object): The transaction object containing the necessary details.

    • to (String): The recipient address.

    • value (String): The amount of value to send (in wei).

    • data (String): The data payload for the transaction.

Example

const transaction = {
  to: "0xRecipientAddress",
  value: "0",
  data: "0xYourData"
};

gassless.sendTransaction(transaction)
  .then(response => console.log("Transaction sent:", response))
  .catch(error => console.error("Transaction failed:", error));

getTransactionStatus

Retrieves the status of a specific transaction.

Parameters

  • transactionHash (String): The hash of the transaction to query.

Example

const transactionHash = "0xYourTransactionHash";

gassless.getTransactionStatus(transactionHash)
  .then(status => console.log("Transaction status:", status))
  .catch(error => console.error("Failed to retrieve status:", error));

getBalance

Fetches the balance of an account.

Parameters

  • address (String): The address of the account to query.

Example

const address = "0xYourAccountAddress";

gassless.getBalance(address)
  .then(balance => console.log("Account balance:", balance))
  .catch(error => console.error("Failed to retrieve balance:", error));

addModule

Adds a module to a Smart Account.

Parameters

  • moduleAddress (String): The address of the module to add.

  • accountAddress (String): The address of the Smart Account.

Example

const moduleAddress = "0xModuleAddress";
const accountAddress = "0xSmartAccountAddress";

gassless.addModule(moduleAddress, accountAddress)
  .then(response => console.log("Module added:", response))
  .catch(error => console.error("Failed to add module:", error));

removeModule

Removes a module from a Smart Account.

Parameters

  • moduleAddress (String): The address of the module to remove.

  • accountAddress (String): The address of the Smart Account.

Example

const moduleAddress = "0xModuleAddress";
const accountAddress = "0xSmartAccountAddress";

gassless.removeModule(moduleAddress, accountAddress)
  .then(response => console.log("Module removed:", response))
  .catch(error => console.error("Failed to remove module:", error));

listModules

Lists all modules associated with a Smart Account.

Parameters

  • accountAddress (String): The address of the Smart Account.

Example

const accountAddress = "0xSmartAccountAddress";

gassless.listModules(accountAddress)
  .then(modules => console.log("Modules:", modules))
  .catch(error => console.error("Failed to list modules:", error));

deploySmartAccount

Deploys a new Smart Account contract.

Parameters

  • ownerAddress (String): The address of the owner of the new Smart Account.

  • factoryAddress (String): The address of the Smart Account Factory contract.

Example

const ownerAddress = "0xOwnerAddress";
const factoryAddress = "0xFactoryAddress";

gassless.deploySmartAccount(ownerAddress, factoryAddress)
  .then(smartAccount => console.log("Smart Account deployed:", smartAccount))
  .catch(error => console.error("Failed to deploy Smart Account:", error));

getSmartAccount

Retrieves details of a Smart Account.

Parameters

  • accountAddress (String): The address of the Smart Account.

Example

const accountAddress = "0xSmartAccountAddress";

gassless.getSmartAccount(accountAddress)
  .then(accountDetails => console.log("Smart Account details:", accountDetails))
  .catch(error => console.error("Failed to retrieve Smart Account details:", error));