How to develop your first digital currency transfer

Yasmine Moustatia
Mixin Network
Published in
4 min readDec 5, 2018

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 botthe 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 to Enjoy!. The user tells the robot that the assets 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

smtmThe directive means show me the money.Thus, when a user enters smtmwhen I let users send money to the robot. The effect is as follows:

First, we want OnMessageto join in on the function stsmparse command:

It involves a function Transferthat 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 RecipientIdamount Amount, currency AssetId, notes Memoand other information needed to fill TransferInputthe structure in; and TrackIda 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.CreateTransferto initiate a direct transfer.

In this function, the bot framework does a lot of trouble for us. You can read in-depth CreateTransfersource ( 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 CNBAssetIDvalue. The answer is in this section.

Similarly, we need to address assetsinstruction

And then implement ShowAssetsthe 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 accessTokenis a function SignAuthenticationTokenof 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.AssetListto get a list of the assets. This function will return an Assetstructure of a list, a detailed analysis is as follows:

If you have some sort of robot purse money, you can AssetIdcoin a corresponding ID to get. However, in this article we are only concerned about Symboland Balance, I created a assetsBufferlist 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 7000101423a 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 .

--

--