Transaction Prompts
Configure user-facing transaction confirmation dialogs
Overview
Transaction Prompts give app the option to show users a capsule-managed prompt to manually approve or deny any transaction or message signing events.
This feature is required when interacting with wallets created outside your app, but can also be turned on for all wallets/transactions in your application. We recommend enabling this feature if you prefer not to implement transaction approval/display flows, or if you prefer users to explicitly approve every transaction on an embedded wallet.
How it Works
Transaction Prompts are mandatory in the following scenarios
- Wallet Interaction: When a user attempts to sign a message or execute a transaction using their wallet in an application that is different from where the wallet was created.
- Multi-Application Transactions: After a wallet has been used across multiple applications, any subsequent transactions will prompt the user for approval. This ensures that the user is aware of and consents to all interactions involving their wallet, regardless of the application being used.
To turn on Transaction Prompts for all transactions/wallets, enable “Always show transaction prompts” for your API key in the Developer Portal
User Interaction
When a transaction or message signing event is initiated, users will see a popup containing the following details:
- Message Details: An encoded string representing the message.
- Transaction Details:
From
: The wallet address initiating the transaction.To
: The recipient wallet address.Amount
: The number of tokens being transferred.Action
: The specific action being performed (e.g., token transfer, minting an NFT).Conversion Rates
: Relevant exchange rates if applicable.Chain Information
: Information about the blockchain being used.
Technical Details
The feature is enabled by default when using the signMessage
or signTransaction
functions, either directly or
through supported signer libraries (e.g., Ethers, Cosmos).
There is a default 30-second timeout for approvals. If this does not work for your use case, please reach out to the Capsule team for instructions on overriding this value.
Transaction Events and Statuses
- On Approval: If the user approves the transaction or no approval is necessary, the
signMessage/signTransaction
function will return aSuccessfulSignatureRes
result, which will contain the signature. - On Denial or Timeout: If the user denies the transaction or the timeout is reached, a
TransactionReviewError
will be thrown that includes thetransactionReviewUrl
that must be handled by the partner implementing the feature.
Error Handling
When implementing Transaction Prompts, various errors can arise during the signing process. It’s important to handle these errors gracefully to ensure a smooth user experience. Below are common scenarios and recommended handling strategies:
1. Transaction Denied
Description: The user denies the transaction or message signing request.
Error Handling:
2. Timeout Reached
Description: The user does not respond to the popup within the configured timeout period. This returns an addition
property of transactionReviewUrl
and pendingTransactionId
pendingTransactionId
- Can be used in conjunction with thegetPendingTransaciton
function available via the CoreCapsule class (or WebCapsule, by extension). If it does not exist, that means the user has denied the transaction request.transactionReviewUrl
- Can be used to open a popup if desired, which will present the user with the sign message / transaction popup.
Error Handling:
EVM Transaction Examples
Setting Up Ethers Signer
First, initialize the Ethers signer with your Capsule instance. This creates a signer that can be used for transactions on EVM networks.
Configuring EVM Transaction
Next, construct your transaction object. This defines all parameters needed for your transaction, such as the recipient address, amount, and gas settings.
Sending EVM Transaction
Finally, send your transaction using the signer. Make sure to implement proper error handling for failed transactions.
Cosmos Transaction Examples
Setting Up CosmJS Signer
First, create a CosmJS signer with your Capsule instance and connect it to a Stargate client. This setup enables interaction with Cosmos-based networks.
Configuring Cosmos Transaction
Next, prepare your transaction configuration. For this example, we’ll set up a token transfer with the appropriate denominations and fees.
Sending Cosmos Transaction
Finally, execute the transaction using the client. The example includes comprehensive error handling for common scenarios like user denial and timeouts.
Each example follows a three-step process: 1. Set up the signer 2. Configure the transaction 3. Execute the transaction with proper error handling
Was this page helpful?