I’m @Lyric and this tutorial was written at the request of Mixin COO @Mint to show engineers outside the blockchain world how to develop their own blockchain applications based on Mixin Network in the simplest way.

This is the first in a series of tutorials. If you are interested in this article, you can:

Subscribe to my blog lyric.im subscribe to my press. one column follow my public account, search iamlyricw or give compliments at the end of this post with some digital currency for easy access to subsequent updates.

From BTC to ETH to EOS, I believe that many engineers have some understanding of blockchain and have heard about the story. The technology itself, whether it is BitCoin’s basic technical model, or the smart contract starting from ETH, or the unique architecture of EOS — may make engineers who are first in touch feel a little uncomfortable, and developing Dapp also becomes difficult.

In fact, each public chain (claims to) have its own unique application scenario, and specific techniques are proposed for this. For developers, these techniques, which involve complex cryptography, become barriers to entry. What Mixin does is smooth out all the differences in the “transaction” aspect of the public chain and focus on the “transaction” itself.

In Mixin Network, you can easily add the attribute of “digital currency” to your project by using the most familiar technology stack and protocol, and realize “retail, tipping, currency transaction” and other “transaction” related functions. Mixin Network’s DAG Network can also use Mixin Network’s DAG Network to add the (broad) “blockchain” attributes to their own projects, to achieve “copyright, storage, traceability, information disclosure” and all other “blockchain” related functions.

To sum up, Mixin networks make it easy to implement your ideas on a blockchain without having to pay attention to a lot of tedious technical details.

Tips:

Dapp is a Decentralized Application[^1] abbreviation. Dapps are thought to be written by smart contracts — code that runs on a blockchain.

Mixin takes a different view. Mixins’ supporters believe in the Unix philosophy [^2] of “let a program do one thing well.” Mixins only need to do one thing “Transaction” well, so mixins do not support smart contracts. That’s why you can write applications using a technology stack you’re familiar with, not just a handful of programming languages.

To start, you need to register your App with the Mixin Network. Developers in the center of the Mixin developers. Mixins. One/dashboard, submit icon, name, description, basic information such as the URL to complete registration. This is very similar to a common open service.

After registering, Click here to generate… To produce necessary information such as keys, each part is shown in the figure below:

Mixin networks treat the App as a User, so the User Id is used to uniquely identify the App on the Network. Each App has its own asset account, and direct transfer to this User Id will enter into the account.

The following information, such as Client Secret, PIN, SessionId, PIN Token, Private Key, etc., are used to operate accounts, such as updating information, transferring money, checking accounts, etc., which we will use later. Make sure you remember them and don’t let them out.

I pre-registered a Hello Bot with Mixin Id 7000101423. You can add a friend experience to Mixin Messenger.

Hello world. Next, let’s write Hello world.

Task description: The user said sync to the robot in Mixin Messager, and the robot replied ack.

For simplicity, I will use MixinNetwork’s Bot SDK in my project: github.com/MixinNetwor… Golang language for programming. So, I’m going to assume that you already have a Golang development environment in place and know how to program in Golang.

  1. The development environment of this paper is macOS, and Golang version is GO1.11.2.

Let’s start by installing the Bot SDK

$go get -u github.com/MixinNetwor… Next we may need to install other dependent modules, please use the Go Get command to install, I won’t go into the details.

Prepare a directory for your project and source code. I’ll call it Hello-bot. Create config.yml to store the configuration. Finally, create main.go under Hello-bot, where the main code will be.

cd hello-bot Before we get started, understand how the Mixin Messenger bot works.

While Mixin Messenger’s assets are built on top of the Mixin Network, its users and messaging systems are separate. When chatting with Mixin Messenger, messages are relayed by the server.

From the server’s point of view, the robot is just like an ordinary user participating in a chat. Therefore, when chatting with the robot, the message will be forwarded by the server to the machine where the robot resides for processing and reply by the robot program.

Since the robot acts like a regular user, it also has its own wallet (visible on the App Dashboard). Therefore, when it comes to money transfer, the robot can operate its own account through Mixin Network, conduct money transfer and other operations by itself.

  1. In the previous chapter, “Register your App”, we got the robot’s Id and private key and needed to write it to the config file config.yml:

client_id: YOUR CLIENT ID client_secret: YOUR CLIENT SECRET session_id: YOUR SESSION ID pin: YOUR PIN pin_token: YOUR PIN TOKEN private_key: | —–BEGIN RSA PRIVATE KEY—– … —–END RSA PRIVATE KEY—– Enter one by one according to the previous information. The private key private_key is a multi-line text. Be sure to follow YAML’s multi-line text syntax and align each line.

In the source code, I provide config.example.yaml, which can be modified for your configuration file.

  1. Receiving messages The core part of a robot is the message loop. The message loop constantly checks the server’s message queue to see if any new messages are pushed to it.

In the main function of main.go, we use the NewBlazeClient method to create the robot client. Client is a module-level variable for other function calls:

// Create a bot client client = bot.NewBlazeClient( config.GetConfig().ClientID, config.GetConfig().SessionID, The config.getConfig ().privateKey) config module takes care of reading the necessary configuration from config.yml.

Then use client.loop to open the message Loop. The key handler functions are defined in the interface handler, implemented as OnMessage

// Start the loop for { if err := client.Loop(ctx, handler); err ! = nil { log.Printf(“Error: %v\n”, err) } log.Println(“connection loop end”) time.Sleep(time.Second) } type Handler struct{} … func (r Handler) OnMessage(ctx context.Context, msgView bot.MessageView, botID string) error { … } msgView is the key parameter, which contains all information related to the message. In the SDK source code, it is defined as follows:

Type MessageView struct {ConversationId string // session ID UserId string // UserId MessageId string // MessageId Category String // Message type, such as text, picture or video Data String // message Data, Status String // Message Status Source String CreatedAt time. time UpdatedAt time. time} Contains all information required for a message.

When a robot processes a message, it needs to disassemble the msgView and then respond.

Func (r Handler) OnMessage(CTX context. context, msgView bot.MessageView, botID String) error {// We only handle PLAIN_TEXT messages, And only answer the current conversation. if msgView.Category == bot.MessageCategoryPlainText && msgView.ConversationId == bot.UniqueConversationId(config.GetConfig().ClientID, msgView.UserId) { var data []byte var err error if data, err = base64.StdEncoding.DecodeString(msgView.Data); err ! = nil { log.Panicf(“Error: %s\n”, err) return err } inst := string(data) log.Printf(“I got a message from %s, it said: %s\n”, msgView.UserId, inst) } … } first we make sure that only text messages are processed, so msgview.category is evaluated first. Then use UniqueConversationId to determine if the message came from the session.

Then msgView.Data is decoded Base64 to obtain the message content, which is saved in the variable INst.

  1. Reply message Now let’s process the message. In OnMessage, determine the contents of the inST:

if “sync” == inst { // Sync? Ack! Respond(CTX, msgView, “ack”) else {Respond(CTX, msgView, defaultResponse)} Respond(CTX, msgView, “ack”) If not sync, reply with a default text.

The implementation of the reply is in the Respond function, which is very simple:

func Respond(ctx context.Context, msgView bot.MessageView, msg string) { if err := client.SendPlainText(ctx, msgView, msg); err ! = nil {log.panicf (“Error: %s\n”, err)}} just call the robot client client.sendPlainText to reply with a sentence specified by the variable MSG.

The effect is as follows:

And you’re done with a robot that can talk to you. By adding more logic to OnMessage, you can make it do more than just reply to a word.

The Mixin Id of Hello Bot is 7000101423. You can add it to Mixin Messenger as a friend experience.

The source code for Hello Bot can be found at github.com/fox-one/hel… To obtain.

In the next chapter, I will add the ability to handle money transfer for Hello Bot.

The Mixin Network Developer Contest is now open, so join us!

The purpose of this competition is to build more excellent and creative works based on Mixin Network.

Mixin Network, a technical solution that provides lightning Network services for all premium digital currencies. Mixin Network inherits the UTXO structure of Bitcoin. By combining mature aBFT, POS and DAG technologies, and combining Intel hardware signature mechanism and high-speed data center, Mixin Network realizes a highly secure distributed accounting Network with ultra-high capacity, ultra-fast confirmation.

Official website address: official website entry

This competition will be open to excellent developers around the world and encourage more developers to develop applications based on Mixin: for example, trading solutions based on Mixin Network; Mixin Messenger all-currency wallet application, robot development; The use of OceanONE exchange engine, etc., to innovate products and solutions in different industries.

Current product cases based on Mixin Network:

Converged Digital Asset transactions and wallets: Fox (fox.one/zh/)

Japan’s largest market tool app: Coinview

Open source encrypted digital wallet: Mixin Messenger

Mixin Messenger based applets example:

Exin (MixinID:7000101276)

A simple and fun slot machine: Slotin (MixinID:7000101605)

Can send digital currency red envelope small program: value red envelope (MixinID:7000100089)

The world’s first online payment mall that only accepts digital currency: TokenMall (MixinID:7000101403)

The competition is open to all developers with no restrictive questions, and mixin-based solutions can be entered.

Competition stage

  • Registration begins (November 14, 2018)

  • Registration deadline (3 January 2019)

  • Submission deadline (January 4, 2019)

  • Award Results (January 10, 2019)

Competition bonus

The first prize (1 winner) is equivalent to 300,000 yuan; The second prize (2 winners) is equivalent to 100,000 yuan; The third prize (3 winners) is equivalent to 50,000 yuan. Award of Excellence (14 winners) : 25XIN (worth about 25,000 YUAN) for each excellent project selected

The rules

1. The maximum number of participants in a team is 5. All registered team members are deemed to have agreed to the competition agreement

2. Registration will start from November 14, 2018 to 23:59, January 3, 2019.

3. The time for submitting the work code is from November 14, 2018 to 23:59, January 4, 2019. Those who fail to submit the code before the deadline will be deemed to have abandoned the competition.

4. Participants should develop based on Mixin Network technology platform.

5. Mixin Network is a community where developers can freely form teams to communicate and discuss, collaborate in creation, and turn ideas into reality.

6. The submitted work must contain executable programs and codes.

Related: Mixin official developers guide and API documentation: developers. Mixins. One/API,

Mixin official code: github.com/MixinNetwor… .

IO /mixin-netwo… Mixin-network.gitbook. IO /mixin-netwo…

Introduction of guest judges

Xiaodong Feng: CEO of Mixin Network, former technical partner of Yijia Technology, China’s leading mobile video technology and service provider. Li Lin: Director of Mixin Labs, senior blockchain technology expert, full stack engineer, with rich experience in project development and management.

Mr. Huo: PRESS. One CTO has years of experience in development, architecture and team management in the technology and Internet sectors.

Jeffrey Wernick: Uber, an early angel investor in Airbnb, a strong believer in Bitcoin, and a noted investor.

Dr. Joseph Liu: The inventor of the Monroe Coin algorithm and chief scientist of HCASH.

Dr. Jiangshan. Yu was awarded “Outstanding Doctoral Scholar Award of Chinese Government” on April 30, 2017.

partners

Welcome to join Mixin Network wechat official group for understanding and consultation; Exchange development experience with the boss and earn a large bonus.