Guide: Wallet Trade Integration
Token Support
If your wallet fully supports CIP-56 tokens you can freely integrate all Tradecraft pools for trading, along with add and remove liquidity options (which return CIP-56 compliant Tradecraft LP tokens).
If your wallet supports only a whitelist of Canton tokens you will need to manually limit your interface to only allow trading of your wallet's supported tokens.
Pools API
To build a trading interface that supports all pools listed on Tradecraft, start by using the GET /pools API to fetch a list of all pools. Note that multi-hop trades are not yet supported.
To get a list of tradable token pairs for a given token, run a reduce function on the list of pools and construct a mapping of each unique token to a list of other tokens. Every time a token appears in a pool entry, add it's paired token to its list of tradable tokens. With the two pools we have online now, your output would look like this:
const tradableTokens = {
'CC': ['USDCx', 'CBTC'],
'USDCx': ['CC'],
'CBTC': ['CC']
}Now you can create a widget with token drop-downs similar to a standard swap widget that looks something like the below image. Each entry in tradableTokens can be added to the first drop-down, and the second drop-down can be populated with the array value for that token.

Quote API
Important
While the API is currently named "quote", these quotes should be presented to users as estimates. Since the on-chain portion of a trade is only initiated after the user sends funds and after Tradecraft gets to their order and begins execution, the price returned from the quote API may not be the price the user receives. A solution for this is in progress.
There are two API's for getting trade quotes–one to specify amount in, and one to specify amount out. Use either or both as your interface requires. For example in the widget above, the API for amount in would be used when the user types in the first input, showing response in the second, and when the user types in the second input, the response would be shown in the first input. Both APIs can be found on the Quotes API page.
Trade Addresses
The official source of Tradecraft Pool Addresses can be found on our Pools & Pool Addresses page. You will need to create a mapping from the user's selected tokens to get the correct Pool Address.
Depending on your chosen interface, you may either present the Pool Address to the user, or obscure these inner workings and send the tokens behind the scenes. Note that with the later option, the user will still need to manually accept incoming CIP-56 tokens (excluding CC), unless you have built a custom automation to accept those transfers.
Last updated
Was this helpful?
