Payments
Send a payment
Send a payment between users using any combination of chains or tokens. thirdweb Payments handles the conversion between currencies into your app or users' destination of choice.
To get started, lets generate a payment for 10 USDC on Optimism, paid with USDT on Arbitrum.
The prepared quote will contain all kinds of details about the payment, including the transactions to execute it.
You can execute the included transactions using the wallet of your choice. In the next section, we'll execute this prepared quote using thirdweb Wallets.
This step assumes you already have a thirdweb wallet logged in. To learn how to setup wallets, see the Wallets getting started guide.
To execute a single transaction, all we need to do is call sendAndConfirmTransaction
with the transaction and user's wallet.
However, prepared payments might contain multiple transactions. Approvals, swaps, and any other pre-execution steps are computed for you and included in the returned transactions. Lets wrap our transaction execution in a loop so we account for all steps.
This will execute the transactions in order, but it might not work yet. Payment transactions that are cross-chain require both an origin and a destination transaction. To account for this, thirdweb Payments have a special status function allowing you to get the end to end status of a buy, sell, or transfer. Lets wait for the cross-chain transactions to be fully completed in our loop.
You can determine the type of a transaction by checking the action
field.
Once this code completes, your payment has been fully executed. Payments normally take just a few seconds to complete, but can take as long as 10 minutes for less common chains.
- Other auth strategies
- Sponsor Gas
- Implement Sign In with Ethereum
- External Wallets (e.g. MetaMask, WalletConnect, Coinbase Wallet, etc.)