Skip to content
Gasless Transactions
Gas Station Network

Overview

Gas Station Network (GSN) is a protocol that enables gasless transactions without a smart contract wallet. GSN is not compatible with all decentralized applications but can be a powerful option if you have set up your smart contracts to be compatible. You can learn more about GSN here.

Getting Started

Create an SDK Instance

ES Modules/Typescript

import { GsnV1Provider } from "@simplecrypto/relay-provider";

const gsnProvider = new GsnV1Provider(window.ethereum, {
	baseURL: "https://api.simplecrypto.dev",
});

CommonJS

const { GsnV1Provider } = require("@simplecrypto/relay-provider");

const gsnProvider = new GsnV1Provider(window.ethereum, {
	baseURL: "https://api.simplecrypto.dev",
});

Send a Transaction through GSN

import { ethers } from "ethers";
import { GsnV1Provider } from "@simplecrypto/relay-provider";

const gsnProvider = new GsnV1Provider(window.ethereum, {
	baseURL: "https://api.simplecrypto.dev",
});

const web3Provider = new ethers.providers.Web3Provider(gsnProvider);

const myContract = new ethers.Contract(contract_address, contract_abi, web3Provider);

const txResponse = await myContract.doCoolFunction();
const txReceipt = await txResponse.wait();

API Reference

GsnV1Provider does not add any additional functions to the RelayProvider. It only overrides the request function to submit transactions through GSN as we’ll as check the transaction receipt for any reverts within the transaction.

Constructor

new GsnV1Provider(provider: ExternalProvider, providerOptions: ProviderOptions, options?: GsnV1ProviderOptions)

Arguments

ParameterTypeDescription
externalProviderExternalProviderA wallet’s rpcProvider. Typically this will be an https://eips.ethereum.org/EIPS/eip-1193 although legacy providers are also supported.
providerOptions.baseURLstringThe baseURL for the Simple Crypto API. This will be the URL you’ve set up in the Proxy API setup.
providerOptions.authToken?string(Optional) Your Simple Crypto API token. It is highly recommended that you do not use this option client-side in production as you will expose your API key. This option can be useful for testing in development, though.
providerOptions.addressOrIndex?stringnumber
options.relayHub?stringThe address of the relay hub contract. The default is 0xD216153c06E857cD7f72665E0aF1d7D82172F494
options.fallbackGasLimit?BigNumberstring
Last updated on February 7, 2023