A trade is the act of converting one asset into a different asset. A
trade is initiated from a wallet or address and the resulting
asset is sent back to the same source.To trade from one asset to another, ensure that the address contains sufficient ETH to pay for
transaction fees, and sufficient funds of the asset you are trading from.Crypto transactions take varying amounts of time—anywhere from hundreds of milliseconds, to tens of minutes, depending on the blockchain network and wallet set-up. For example, transactions on Bitcoin can take upwards of 30 minutes, while transactions on Base take a second or two.Once your address has ETH in it, we can call the trade function to trade ETH for USDC:
SDK DocumentationYou can refer to the Trade class SDK docs for a full list of supported methods.
Copy
Ask AI
// Create a wallet on `base-mainnet`let wallet = Wallet.create({ networkId: Coinbase.networks.BaseMainnet });// Fund the wallet with ETH on `base-mainnet` from an external source.// Trade 0.00001 Ether for USDC.let trade = await wallet.createTrade({ amount: 0.00001, fromAssetId: Coinbase.assets.Eth, toAssetId: Coinbase.assets.Usdc});// Wait for the trade to settle.await trade.wait();
You can use status to query a crypto transaction’s status.
A common case is to check whether the transaction succeeded or failed.
Copy
Ask AI
let status = TransactionStatus.PENDING;while (status === TransactionStatus.PENDING) { // Do something here. // .... // Check the status of the trade. status = await trade.getStatus();}