Path: blob/main/docs/versioned_docs/version-v0.26/02-guide/07-interchange/02-init.md
1007 views
---
---
App Init
Initialize the Blockchain
In this chapter, you create the basic blockchain module for the interchain exchange app. You scaffold the blockchain, the module, the transaction, the IBC packets, and messages. In later chapters, you integrate more code into each of the transaction handlers.
Create the Blockchain
Scaffold a new blockchain called interchange
:
A new directory named interchange
is created.
Change into this directory where you can scaffold modules, types, and maps:
The interchange
directory contains a working blockchain app.
A local GitHub repository has been created for you with the initial scaffold.
Next, create a new IBC module.
Create the dex Module
Scaffold a module inside your blockchain named dex
with IBC capabilities.
The dex module contains the logic to create and maintain order books and route them through IBC to the second blockchain.
Create CRUD logic for Buy and Sell Order Books
Scaffold two types with create, read, update, and delete (CRUD) actions.
Run the following Ignite CLI type
commands to create sellOrderBook
and buyOrderBook
types:
The values are:
amountDenom
: the token to be sold and in which quantitypriceDenom
: the token selling price
The --no-message
flag specifies to skip the message creation. Custom messages will be created in the next steps.
The --module dex
flag specifies to scaffold the type in the dex
module.
Create the IBC Packets
Create three packets for IBC:
An order book pair
createPair
A sell order
sellOrder
A buy order
buyOrder
The optional --ack
flag defines field names and types of the acknowledgment returned after the packet has been received by the target chain. The value of the --ack
flag is a comma-separated list of names (no spaces). Append optional types after a colon (:
).
Cancel messages
Cancelling orders is done locally in the network, there is no packet to send.
Use the message
command to create a message to cancel a sell or buy order:
Use the optional --desc
flag to define a description of the CLI command that is used to broadcast a transaction with the message.
Trace the Denom
The token demons must have the same behavior as described in the ibc-transfer
module:
An external token received from a chain has a unique
denom
, referred to asvoucher
.When a token is sent to a blockchain and then sent back and received, the chain can resolve the voucher and convert it back to the original token denomination.
Voucher
tokens are represented as hashes, therefore you must store which original denomination is related to a voucher. You can do this with an indexed type.
For a voucher
you store, define the source port ID, source channel ID, and the original denom:
Create the Configuration for Two Blockchains
Add two config files mars.yml
and venus.yml
to test two blockchain networks with specific token for each.
Add the config files in the interchange
folder.
The native denoms for Mars are marscoin
, and for Venus venuscoin
.
Create the mars.yml
file with your content:
Create the venus.yml
file with your content:
In order to run two blockchains side by side on a single machine, you need to start them on different ports. venus.yml
has a validators configuration that stars services HTTP API, gRPC, P2P and RPC services on custom ports.
After scaffolding, now is a good time to make a commit to the local GitHub repository that was created for you.
Implement the code for the order book in the next chapter.