Authorization

Use increased rate limits with our SDK

A system for obtaining and managing increased API rate limits through request authorization.

Initialization

const afSdk = new Aftermath("MAINNET");
await afSdk.init(); // initialize provider

const auth = afSdk.Auth();

Rate Limits

Default rate limit: 1000 requests per 10 seconds.

To request increased limits:

  1. Open a ticket with:

sui-address: <your-sui-address>
rate-limit-requests: [<sdk-call>: <desired-rate-limit>]

Methods

Initialize with Private Key

const keypair = Helpers.keypairFromPrivateKey("your-private-key");

const stopAuth = await auth.init({
	signMessageCallback: async ({ message }) => {
		const { signature } = await keypair.signPersonalMessage(message);
		return { signature };
	},
	walletAddress: keypair.toSuiAddress(),
});

// Make authorized requests
const pools = await afSdk.Pools().getAllPools();

// Stop authorization
stopAuth();

Initialize with Sui Keystore

const stopAuth = await auth.initFromSuiKeystore({
	walletAddress: "0x...",
	path: "~/.sui/sui_config/sui.keystore", // Optional custom path
});

// Make authorized requests
const pools = await afSdk.Pools().getAllPools();

// Stop authorization
stopAuth();

Types

interface AuthInitOptions {
	signMessageCallback: (args: { message: Uint8Array }) => Promise<{
		signature: string;
	}>;
	walletAddress: string;
}

interface SuiKeystoreOptions {
	walletAddress: string;
	path?: string;
}

Example Usage

const afSdk = new Aftermath("MAINNET");
await afSdk.init();

// Initialize with private key
const keypair = Helpers.keypairFromPrivateKey("your-private-key");
const stopAuth = await afSdk.Auth().init({
	signMessageCallback: async ({ message }) => {
		const { signature } = await keypair.signPersonalMessage(message);
		return { signature };
	},
	walletAddress: keypair.toSuiAddress(),
});

// Make authorized requests
const pools = await afSdk.Pools().getAllPools();
const prices = await afSdk.Prices().getCoinPrice({
	coin: "0x2::sui::SUI",
});

// Clean up
stopAuth();

Last updated