How to develop your first digital currency transfer
This series of tutorials are designed to show engineers outside the blockchain field how to develop their own blockchain applications in the easiest way, relying on the Mixin Network.
Your first digital currency transfer
In the last installment , I showed you how to get in touch with the Mixin Network in the easiest way: a robot hello bot
. This robot is able to respond to user input in Mixin Messenger.
Trading is a core issue addressed by the Mixin Network. So in this issue, I will add to the hello bot
the basis, the funds operation.
Task Description: The user tells the robot in Mixin Messenger that the
smtm
robot replies to the user and transfers the remarks toEnjoy!
. The user tells the robot that theassets
robot replies to the list of assets in its wallet.
By reading this article, you will know how to make money transfers such as transfers in the Mixin Network.
Again , this tutorial requires you to know how to write programs in Golang .
1. Processing transfer instructions smtm
smtm
The directive means show me the money.
Thus, when a user enters smtm
when I let users send money to the robot. The effect is as follows:
First, we want OnMessageto
join in on the function stsm
parse command:
It involves a function Transfer
that is responsible for sending a sum of money to the person who is currently sending the message and writing it in the note Enjoy!
.
The target transfer RecipientId
amount Amount
, currency AssetId
, notes Memo
and other information needed to fill TransferInput
the structure in; and TrackId
a random UUID, used to ensure that the transfer operation is executed only once. Finally, we will be ready before the robot ID, SessionID, private key and PIN information such as parameters, call this functionbot.CreateTransfer
to initiate a direct transfer.
In this function, the bot framework does a lot of trouble for us. You can read in-depth CreateTransfer
source ( here ). Knowing that in order to prepare a transfer, the framework has helped us do a lot of extra work. If you want to know, don't worry, because it will be used next.
2. Processing asset instructions assets
The purpose of this command is to list the amount of all assets in the robot wallet, as well as related asset information. A few days ago i got asked how I knew the amount of the transfer CNBAssetID
value. The answer is in this section.
Similarly, we need to address assets
instruction
And then implement ShowAssets
the function:
This function is more complex to achieve a little bit, because bot.AssetList
did not help us to do extra work, it needs the second parameter accessToken
is a function SignAuthenticationToken
of the product, we need to manually generate it.
Its main function is to use the Key of the robot to generate a token to access the protected resource. For a detailed explanation of this function, please refer to the Authentication Token section of the official website document .
With accessToken
, we can call bot.AssetList
to get a list of the assets. This function will return an Asset
structure of a list, a detailed analysis is as follows:
If you have some sort of robot purse money, you can AssetId
coin a corresponding ID to get. However, in this article we are only concerned about Symbol
and Balance
, I created a assetsBuffer
list of assets used to traverse the two into Buffer After formatting, the final output to the chat window.
summary
Hello Bot’s Mixin Id is 7000101423
a buddy experience that can be added to Mixin Messenger.
The source code for Hello Bot is available at https://github.com/fox-one/hello-bot
In the next chapter, I will add money-making features to Hello Bot .