Skip to main content
The SKALE Gasless SDK enables gasless transactions on SKALE Network, allowing users to send transactions without needing to hold gas tokens in their wallets. This SDK supports both TypeScript/JavaScript and Rust implementations.

Background on Gasless Transactions

  • Gasless transactions utilize SKALE Network’s native Proof-of-Work mechanism that uses a magic number to slot into the gas price field of a transaction
Gasless transactions may not be compatible directly with wallets that explicility require and check for native gas balance.

Installation

# NPM
npm add @dirtroad/gasless

# Yarn
yarn add @dirtroad/gasless

# PNPM
pnpm add @dirtroad/gasless

# Bun
bun add @dirtroad/gasless

Basic Usage

The core functionality involves generating a magic gas price that allows for gasless transactions on SKALE Network.
import { mineGasForTransaction } from "@dirtroad/gasless";

import { createPublicClient, createWalletClient, http } from "viem";
import { skaleCalypsoTestnet } from "viem/chains";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";

async function main() {
    const privateKey = generatePrivateKey();
    
    const client = createPublicClient({
        chain: skaleCalypsoTestnet,
        transport: http()
    });

    const wallet = createWalletClient({
        chain: skaleCalypsoTestnet,
        transport: http(),
        account: privateKeyToAccount(privateKey)
    });

    const { gasPrice } = await mineGasForTransaction(100_000, wallet.account.address, 0);

    const res = await wallet.sendTransaction({
        to: "0x62Fe932FF26e0087Ae383f6080bd2Ed481bA5A8A",
        data: `0x0c11dedd000000000000000000000000${wallet.account.address.substring(2)}`,
        gas: BigInt(100_000),
        gasPrice: BigInt(gasPrice)
    });

    const receipt = await client.waitForTransactionReceipt({
        hash: res
    });

    console.log("Receipt of gasless tx: ", receipt);
}

main()
    .catch((err) => {
        console.error("err: ", err);
        throw err;
    })

Important Notes

This SDK and functionality is built and exists solely for use with SKALE Chains with Proof-of-Work enabled. This does not work with non-sChains or sChains that have chosen to disable Proof-of-Work like SKALE on Base.
The SDK utilizes heavy mathematical operations on the active device CPU.