Increase user engagement and retention by sponsoring transactions

Overview

Use Cases

Shinami's Gas Station API lets you easily sponsor transactions for your users. APT is pulled from a fund you create to power these transactions, managed in Shinami's dashboard.

Shinami facilitates sponsored transactions based on logic determined by you, the app developer. Examples include sponsoring each user's initial transaction(s) for better onboarding and sponsoring transactions of a particular type that you want to encourage.

Authentication, Rate Limits, and Error Handling

Authentication

You authenticate via an access key passed in a header ('X-Api-Key: ACCESS_KEY') or in the request url, e.g. https://api.shinami.com/aptos/gas/v1/ACCESS_KEY. We recommend using a request header and not putting access keys in your request URLs for reduced visibility (in logs, etc).

For more information, including how to set up API access keys, see our Authentication and API Keys guide.

🚧

Call Shinami's Gas Station from your backend server

Shinami Gas Station does not support CORS requests, so you will get a CORS error if you make requests from your frontend. Use your backend server to integrate with Shinami's Gas Station. This limits exposure of your sponsorship access keys. If these keys are leaked, bad actors have the ability to sponsor transactions from your fund until it has been drained or you disable the key in our dashboard.

Rate Limits

Gas Station access keys have a rate limit of 10 QPS. When you surpass this, we return a JSON-RPC error code -32010. We recommend implementing retries with a backoff to handle any rate limits errors that arise. You can also consider batching multiple Move calls into a Move script.

Error Handling

See our Error Reference for guidance on the errors you may receive from our services, including a section on errors specific to the Aptos Gas Station API.

Create and sponsor a transaction

This section shows an example of how to build and sponsor a simple transaction using the Shinami Clients SDK and the Aptos TS SDK. For a high-level image of the sponsorship flow see here. For full sample code showing how to build, sponsor, and submit a transaction, see our Gas Station TypeScript Tutorial

Requirements

  1. Build your transaction with the fee payer address set to 0x0 (this is what happens when you set withFeePayer: true as shown below).
  2. The transaction's expiration timestamp must be set to a time within the next hour (as is required by our Gas Station). When you control the generation of the sender's signature, as with an embedded wallet you control for the user, you can likely use the SDK default, which is 20 seconds from now. When you need to wait on a signature you don't control, as with a connected wallet where the user must approve a signing message, you can explicitly set it as in the example below.

Replace all instances of {{name}} with the actual value for that name

import { GasStationClient } from "@shinami/clients/aptos";
import { Account, Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

// Create an Aptos client and generate an account to act as the sender
const aptos = new Aptos(new AptosConfig({ network: Network.TESTNET }));
const account = Account.generate({});

// Create a Shinami Gas Station client for sponsoring our transactions.
const SHINAMI_TESTNET_GAS_KEY = "{{APTOS_TESTNET_GAS_STATION_ACCESS_KEY}}";
const gasStationClient = new GasStationClient(SHINAMI_TESTNET_GAS_KEY);

// This transaction makes a function call to a module we've deployed on Testnet
const FIVE_MINUTES_FROM_NOW_IN_SECONDS = Math.floor(Date.now() / 1000) + (5 * 60);
const transaction = await aptos.transaction.build.simple({
    sender: account.accountAddress,
    withFeePayer: true,
    data: {
      function: "0xc13c3641ba3fc36e6a62f56e5a4b8a1f651dc5d9dc280bd349d5e4d0266d0817::message::set_message",
      functionArguments: ["test message"]
    },
    options: {
        expireTimestamp: FIVE_MINUTES_FROM_NOW_IN_SECONDS
    }
});

// Send `transaction` to Shinami for sponsorship
let feePayerAuthenticator = await gasStationClient.sponsorTransaction(transaction);

// Note that our SDK updates the transaction's feePayer address on a successful sponsorship
console.log("transaction.feePayerAddress post-sponsorship:", transaction.feePayerAddress);

// Generate the sender's signature (senderAuthenticator below)
    
//  When you submit the transaction, just plug in the response from Gas Station
//   as the `feePayerAuthenticator` argument
const committedTransaction = await aptos.transaction.submit.simple({
    transaction,
    senderAuthenticator,
    feePayerAuthenticator: feePayerAuthenticator,
});

Methods

gas_sponsorTransaction

Description
Sponsor a transaction by having your Shinami Gas Station fund act as the feePayer.

Shinami sponsorship fees: We charge a small fee (in APT) per sponsorship request to cover our costs. For details, visit your Shinami dashboard's Billing tab .

Request Parameters

NameTypeDescription
transactionTypeScript SDK:
AnyRawTransaction

cURL:
String | byte array
TypeScript SDK:
An AnyRawTransaction (the result of a successful call to aptos.transaction.build.simple() or aptos.transaction.build.multiAgent()).

cURL:
BCS-serialized RawTransaction component of an AnyRawTransaction. Can be passed either as an unsigned byte array or a hex string.

Note: the transaction's expiration timestamp must be set to a time within the next hour, in seconds. Otherwise, our service will not sponsor the transaction.
cURL-only
secondarySignerAddresses
[String]Optional array of additional signer addresses. Must be in the exact order. Required for multi-agent transactions.

Example Request Template

The TypeScript example uses the Shinami Clients SDK.

Replace all instances of {{name}} with the actual value for that name

import { GasStationClient } from "@shinami/clients/aptos";

const gas = new GasStationClient("{{gasStationAccessKey}}");

await gas.sponsorTransaction(transaction);
 curl https://api.shinami.com/aptos/gas/v1/ \
-X POST \
-H 'X-API-Key: {{gasStationAccessKey}}' \
-H 'Content-Type: application/json' \
-d '{ 
        "jsonrpc":"2.0", 
        "method":"gas_sponsorTransaction",
        "params":[
            "{{rawTransaction}}",
            "{{secondarySigners}}"
        ],
        "id":1
    }'

Example Response

{
  public_key: { key: { data: [Object] } },
  signature: { data: { data: [Object] } }
}
{
    "jsonrpc":"2.0",
    "result":{
        "feePayer":{
            "address":"0x2cdcec66a48b596c923024102feda5ee759197fe844c5ba56013d3b9a99287b6",
            "signature":[0,32,87,185,212,148,211,30,213,111,144,35,98,238,246,233,212,250,141,34,227,144,171,146,27,203,22,120,200,236,145,94,203,207,64,3,238,3,81,139,240,173,30,31,146,34,145,151,191,54,93,34,206,249,77,214,168,228,65,165,220,65,174,220,137,196,173,168,37,116,136,85,216,217,121,46,1,205,38,147,183,201,252,246,40,62,127,220,20,246,41,244,5,209,109,224,114,189,3]
        }
    },
    "id":1
}

TypeScript SDK Response Fields

Note transaction.feePayerAddress is updated in-place upon a successful return.

TypeDescription
AccountAuthenticatorAccountAuthenticator of the sponsor, to be included in the request to submit the transaction to the chain.

cURL Response Fields

NameTypeDescription
feePayer.addressStringFee payer account address. If desired you can use this to set the transaction's feePayerAddress before obtaining sender and any secondary signer signatures.
feePayer.signatureUnsigned byte arrayBCS-serialized AccountAuthenticator of the fee payer, as an array of unsigned bytes.