This example helps you create messages to convert CW20 tokens to bank tokens on the Injective blockchain. This is particularly useful when you have CW20 tokens and need to convert them to their bank equivalents to perform operations like placing market orders. Note that this flow only works for cw20 tokens and their corresponding factory tokens. This guide will walk you through:Documentation Index
Fetch the complete documentation index at: https://injectivelabs-mintlify-jp-developers-first-half-1777019423.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
- Obtaining the user’s CW20 token balance.
- Creating a message to convert CW20 tokens to bank tokens using ConvertCw20ToBankService
- Executing a market order using the converted bank balance and existing bank balance
Get User’s CW20 Balance
You can perform this using explorer indexer queries.- Find the cw20 address and balance from the result set that you want to convert to a bank factory token
Create CW20 to Bank Conversion Message
- create the
convertMsgusing the steps detailed here in order to convert your CW20 token to a bank factory token. No need to submit the tsx yet.
Create a MsgCreateSpotMarketOrder message
- Create the
msgusing the steps detailed in MsgCreateSpotMarketOrder. No need to submit the tsx yet. - Note that the buy order you create will have access to your converted cw20 balance + existing bank balance. Example:
- If you had 5 Cw20 tokens and 5 bank tokens at a price of $1 each, then the order above will go through because we will convert the cw20 to bank before the chain executes this market order. This will be more clear in the next step.
