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.
/**
* 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);