Skip to content
Gasless Transactions
Custom Gasless Transactions

Overview

Simple Crypto can suppport any gasless transaction pattern. If you want one that we don't offer in our SDK, feel free to add one yourself.

Under the hood, all our solutions use RelayProvider SDK under the hood. This package will be helpful if you want to add custom support for some meta transaction pattern or have some other custom use case.

Getting Started

Installation

# npm
npm i --save @simplecrypto/relay-provider

# yarn
yarn add @simplecrypto/relay-provider

Create an SDK Instance

The examples use MetaMask as the underlying wallet.

ES Modules / Typescript

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

const relayProvider = new RelayProvider(window.ethereum, {
	baseUrl: "https://api.simplecrypto.dev"
});

CommonJS

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

const relayProvider = new RelayProvider(window.ethereum, {
	baseUrl: "https://api.simplecrypto.dev"
});

API Reference

Constructor

new RelayProvider(externalProvider: ExternalProvider, options: ProviderOptions)

ParameterTypeDescription
externalProviderExternalProviderA wallet’s rpcProvider. Typically this will be an https://eips.ethereum.org/EIPS/eip-1193 although legacy providers are also supported.
options.baseUrlstringThe baseUrl for the Simple Crypto API. This will be the URL you’ve set up in the Proxy API setup.
options.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.
options.addressOrIndex?stringnumber

Example

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

const relayProvider = new RelayProvider(window.ethereum, {
	baseUrl: "https://api.simplecrypto.dev"
});

getTransaction(sidOrHash: string): Promise<any>

Query the Simple Crypto API for a transaction.

Arguments

ParameterTypeDescription
sidOrHashstringThe Simple Crypto ID or the hash of the transaction that the user has acknowledged.

Returns

Promise<any> Returns the transaction information from the Simple Crypto API.

getUserTransactions(unacknowledgedOnly: boolean = false): Promise<Array<any>>

Get all the transactions from the current user. Optionally set unacknowledgedOnly to true to only get the transactions that a user hasn’t yet acknowledged.

Arguments

ParameterTypeDescription
addressOrIndex?string, numberThe address or index of the address to be used on the underlying wallet.

Returns

Promise<Array<any>> Returns an array of transactions.

acknowledgeTransaction(sidOrHash: string, acknowledge: boolean = true): Promise<any>

Acknowledge a transaction.

Arguments

ParameterTypeDescription
sidOrHashstringThe Simple Crypto ID or the hash of the transaction that the user has acknowledged.
acknowledgebooleanWhether you want to set the transaction to acknowledged or unacknowledged.

Returns

Promise<any> Returns the response from acknowledging the transaction.

getAccount(): Promise<string>

Get the current account being used by the provider.

Arguments

none

Returns

Promise<string> The current account being used by the provider.

setAccount(addressOrIndex?: string | number): Promise<string>

Set the account to be used with the provider. If addressOrIndex is not provided, we’ll use the address at the first index of the wallet.

This method is useful when a user changes the account that they are using within the app. RelayProvider will not automatically update the account being used so you’ll want to add an event listener that watches for when the user changes the account and call this method with the user’s current account.

Alternatively, you can just initialize RelayProvider right before sending transactions and not have to worry about this.

Arguments

ParameterTypeDescription
addressOrIndex?string, numberThe address or index of the address to be used on the underlying wallet.

Returns

Promise<string> Returns the current account being used.

request(request: { method: string; params?: Array<any> }): Promise<any>

EIP1193 request function. This method supports any Ethereum Json RPC requests. A reference for these requests can be found here. Under the hood, eth_sendTransaction requests will post the transaction to the Simple Crypto API and eth_getTransactionReceipt requests will fetch the transaction from our API.

Arguments

ParameterTypeDescription
request.methodstringThe Ethereum JSON RPC method.
request.params?Array<any>The params associated with the JSON RPC request

Returns

Promise<any>

Last updated on February 7, 2023