A system for obtaining and managing increased API rate limits through request authorization.
const afSdk = new Aftermath("MAINNET");
await afSdk.init(); // initialize provider
const auth = afSdk.Auth();
Default rate limit: 1000 requests per 10 seconds.
sui-address: <your-sui-address>
rate-limit-requests: [<sdk-call>: <desired-rate-limit>]
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();
interface AuthInitOptions {
signMessageCallback: (args: { message: Uint8Array }) => Promise<{
signature: string;
}>;
walletAddress: string;
}
interface SuiKeystoreOptions {
walletAddress: string;
path?: string;
}
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();