Embedded Wallets
SDK
Javascript
How to
Wallet Operation
Cancel Transaction

Cancel Transaction

This method allows you to cancel a transaction from a blockchain network.

Method Signature

async cancelTransaction(config: CancelTransactionConfig): Promise<{ hash: string } | {hash: string, walletToken: string, refreshToken: string}>

Parameters

  • config: CancelTransactionConfig - An object containing the following properties:
    • network (required): Network - The network used for transactions. You can use the Network enum to specify the network.
    • nonce (required): number - A unique number for each transaction. Provide the nonce of the transaction you want to cancel.
    • walletToken (required): string - The wallet token of the wallet to cancel the transaction for.
    • refreshToken (optional): The refresh token for authentication. Use this if you want to allow SDK automatically refresh the wallet token.

Returns

Promise<{ hash: string } | {hash: string, walletToken: string, refreshToken: string}> - The hash of the canceled transaction. If the refresh token is provided, the SDK will automatically refresh the wallet token and return the new wallet token and refresh token.

Example Usage

const hash = await sdk.wallet.cancelTransaction({
  network: Network.ETHEREUM,
  nonce: 1234567890,
  walletToken: 'your-wallet-token',
  refreshToken: 'your-refresh-token', // Optional
});
console.log(hash);

Response Example

{
  "hash": "0x4ec81ca3d6a112bdf991a220ed83458f061f1f818273c93546ea91a4e1d675",
  "walletToken": "your-new-wallet-token",
  "refreshToken": "your-new-refresh-token"
}
ℹ️

The SDK will automatically refresh the wallet token and return the new wallet token and refresh token if the refresh token is provided.

ℹ️

The response is a string representing the transaction hash of the cancellation transaction.

⚠️

Make sure you provide the correct nonce of the transaction you want to cancel. Canceling a transaction with an incorrect nonce may result in unexpected behavior.

Additional Information

  • The cancellation is initiated by sending a new transaction with the same nonce as the original transaction, but with a higher gas price to prioritize it over the original transaction.
  • The success of the cancellation depends on whether the new transaction is mined before the original one.
  • This method requires a valid wallet token in the SDK configuration.

For more information, see the Xellar Cancel Transaction API Documentation (opens in a new tab).