Aftermath
  • Aftermath
    • About Aftermath Finance
      • What are we building?
  • Getting Started
    • Creating an account
      • zkLogin
        • Removing a zkLogin account
      • Sui Metamask Snap
      • Native Sui wallets
    • Dynamic Gas
    • Navigating Aftermath
      • Interacting with your Wallet
      • Viewing your Portfolio
      • Changing your Settings
      • Bridge
      • Referrals
  • Trade
    • Smart-Order Router
      • Agg of Aggs
      • Making a trade
      • Exact Out
      • Fees
    • DCA
      • Why should I use DCA
      • How does DCA work
      • Tutorials
        • Creating a DCA order
        • Monitoring DCA progress
        • Advanced Features
      • Fees
      • Contracts
  • Limit Orders
    • Contracts
    • Fees
  • Pools
    • Constant Function Market Maker
      • Tutorials
        • Depositing
        • Withdrawing
        • Creating a Pool
      • Fees
      • Contracts
      • Audit
  • Farms
    • Afterburner Vaults
      • Tutorials
        • Staking into a Farm
        • Claiming Rewards
        • Unstaking
        • Creating a Farm
      • Architecture
        • Vault
        • Stake Position
      • Fees
      • FAQs
  • Liquid Staking
    • afSUI
      • Tutorials
        • Staking
        • Unstaking
      • Architecture
        • Packages & Modules
        • Entry Points
      • Fees
      • FAQs
      • Contracts
      • Audit
  • Perpetuals
    • Aftermath Perpetuals
      • Tutorials
        • Creating an Account
        • Selecting a Market
        • Creating a Market Order
        • Creating a Limit Order
        • Maintaining your Positions
      • Architecture
        • Oracle Prices
        • Margin
        • Account
        • Trading
        • Funding
        • Liquidations
        • Fees
  • GameFi
    • NFT AMM
      • Architecture
        • Fission Vaults
        • AMM Pools
      • Tutorials
        • Buy
        • Sell
        • Deposit
        • Withdraw
      • Sui Overflow
  • Our validator
    • About us
  • Developers
    • Aftermath TS SDK
      • Utils
        • Coin
        • Users Data
        • Authorization
      • Products
        • Prices
        • Router
        • DCA
        • Limit Orders
        • Liquid Staking
        • Pools
        • Farms
        • Dynamic Gas
    • Aftermath REST API
      • Authorization
  • Egg
    • About Egg
  • Legal
    • Terms of Service
    • Privacy Policy
  • Languages
    • 中文
    • 한국어
  • Links
    • X
    • Telegram
    • Discord
    • Github
    • Medium
    • Aftermath Validator
Powered by GitBook
On this page
  • Initialization
  • Methods
  • Types
  • Example Usage
  1. Developers
  2. Aftermath TS SDK
  3. Products

Dynamic Gas

The DynamicGas class provides methods for allowing any non-SUI coin to be used to pay for gas on any given Transaction on the Sui network.

Initialization

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

const dynamicGas = afSdk.DynamicGas();

Methods

getUseDynamicGasForTx()

This method accepts any completed transaction, which it will modify and return as a sponsored transaction, paying for the sender's gas in SUI, and accepting the payment for this sponsored gas from the sender in the form of the provided gasCoinType.

const { txBytes, sponsoredSignature } = await dynamicGas.getUseDynamicGasForTx({
	tx,
	walletAddress: "0x<user_address>",
	gasCoinType: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
});

Types

/**
 * Represents the response from the dynamic gas service, typically returning
 * updated transaction bytes and possibly a sponsored signature if the
 * transaction gas is being partially or fully sponsored.
 */
export interface ApiDynamicGasResponse {
	/**
	 * The modified transaction bytes that incorporate a gas coin or sponsor information.
	 */
	txBytes: SerializedTransaction;
	/**
	 * A signature used to sponsor or verify the updated transaction, if applicable.
	 */
	sponsoredSignature: string;
}

/**
 * Represents the body payload sent to the dynamic gas service,
 * which includes the serialized transaction and any user-provided
 * gas configuration (e.g., coin type).
 */
export interface ApiDynamicGasBody {
	/**
	 * The serialized transaction block in base64 or similar format.
	 */
	serializedTx: SerializedTransaction;
	/**
	 * The address of the user for whom the dynamic gas is being set.
	 */
	walletAddress: SuiAddress;
	/**
	 * The coin type to be used for gas payment (e.g., "0x2::sui::SUI").
	 */
	gasCoinType: CoinType;
}

Basic Types

/**
 * Represents a serialized transaction in a base64 or similar format.
 */
export type SerializedTransaction = string;

/**
 * Represents a Sui wallet address (e.g., "0x<address>").
 */
export type SuiAddress = string;

/**
 * A string that uniquely identifies a coin type in the Sui network
 * (e.g., "0x2::sui::SUI").
 */
export type CoinType = string;

Example Usage

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

// Create some transaction
const tx = new Transaction();

// Add some move calls to transaction
// ...

// Use USDC to pay for gas instead of SUI
const { txBytes, sponsoredSignature } = await dynamicGas.getUseDynamicGasForTx({
	tx,
	walletAddress: "0x<user_address>",
	gasCoinType: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
});

// Derive updated transaction from response
const updatedTx = Transaction.from(res.txBytes);

// Sign transaction
const signedTxData = await signTransaction({
	transaction: updatedTx,
});

// Create Sui client
const client = new SuiClient({
	transport: new SuiHTTPTransport({
		url: "https://fullnode.mainnet.sui.io:443",
	}),
});

// Execute transaction
const transactionResponse = await client.provider.executeTransactionBlock({
	transactionBlock: signedTxData.txBytes,
	// Requires both user's signature and sponsor's signature
	signature: [signedTxData.signature, sponsoredSignature],
	requestType: "WaitForEffectsCert",
	options: {
		showEvents: true,
		showBalanceChanges: true,
		showEffects: true,
		showObjectChanges: true,
	},
});
console.log("Transaction Response:", transactionResponse);
PreviousFarmsNextAftermath REST API

Last updated 2 days ago