Skip to content
SDKTradingExecute a trade

Trading

When you’re trading assets between profiles, you want to be sure both parties involved in the trade get their due assets or tokens as proposed in the trade. We created a couple of asset management methods to help you with managing assets, but the risk of using these methods is that if you move tokens or assets from profile A to B, and from B to A that one of the transactions could fail.

The trade method minimizes this risk by insuring that either both parties get their due assets, or neither of them will receive anything.

Here’s an example of what the trade method would look like in action.

const profile = await beam.trading.trade({
  initiator: {
    entityId: "profile-id-a",
    tokens: [
      {
        assetAddress: "string",
        amount: "string",
        tokenId: "string",
      },
    ],
  },
  counterparty: {
    entityId: "profile-id-b",
    tokens: [
      {
        assetAddress: "string",
        amount: "string",
        tokenId: "string",
      },
    ],
  },
  sponsor: false, // 👈 This handles the transaction to be self paid
  policyId: "cl..", // 👈 This triggers the custom policy to be used
});
 
// {
//   "status": "success",
//   "type": "custodial",
//   "transactionHash": "string",
//   "explorerUrl": "string"
// }