How to develop your app based on Mixin Network
By: Yasmine Moustatia
Tags: JavaScript, Blockchain, Mixinnetwork, Developer, Java

Introduction

Mixin is a secure, free, lighting fast and private decentralized ledge network. 13 blockchain has been supported（BTC/ETH/EOS/DASH/XRP/XEM/SC/DOGE/BCH/LTC/ZEC/ETC/ZEN ) and support also deposit, withdraw and transfer for more than 46000 assets.

Steps to develop application based on Mixin

0-Pre-request

Download Mixin messenger. Before you start writing your code, it will save you time if you try each function like setup pin, deposit, withdraw and transfer.

Official guide to developers：https://developers.mixin.one/guides

1-Register a developer account

Visit https://developers.mixin.one and click the top right menu, you will login in developer portal after scan the barcode with mixin app camera.

2-Create an app

Your app is a mixin network user. And it can create user on Mixin network too. As developer, you can know the deposit, transaction and withdraw actions done by your app users. You can also get revenues from transactions fees.

Click the button “Create New App”

The home URI: It should be your official site like https://mixin.one, it can be blank.

The OAuth redirect URI: callback url for OAuth. It is required when you want to enable Mixin user login your website, or when you want to access user’s profile inside Mixin messenger.

3-Generate session

Just click the button: “Click to generate a new session” to generate sensitive information include : PIN,Session id, Pin Token, Private Key, you need to keep it safe because Mixin server and the browser did not keep the information at all. And a new set of data will be generated if you click again.

4-Create a user on Mixin network

According to https://developers.mixin.one/api#app_apicreate_user and https://developers.mixin.one/api#documentationauthentication_token , you need to know Session Id generated in last chapter.

You have to put authorized header in all API call. The document is ： https://developers.mixin.one/api#documentationauthentication_token

The app created by you is also an user on Mixin network. So you can also deposit asset into the account, withdraw from it and transfer asset to other user. Of course the app can create its own user too. Developer need to use user’s private key to signing message and matching AES key to manage user’s account. Because every Mixin network user has different session id, private key and other sensitive information. And server will check the account applied by developer and secret session generated based on account’s configuration.

Never use same RSA private key for your app and your users. We recommend each user to have a unique private key. You can see how ocean.one did. An example： GeneratePoolKey method in https://github.com/MixinNetwork/ocean.one/blob/master/example/models/pool_key.go.

Server will return status code 401 if you did not generate the correct Authentication Token

5-Setup PIN code

Pin is six digit number, it must be setup and remembered by user. Mixin server do not save it at all. Server will verify the pin when user want to transfer asset. We strongly recommend you never save pin for user based on security reason. You can see the related API : https://developers.mixin.one/api#apicreate_pin and https://developers.mixin.one/api#documentationencrypted_pin

To help user build muscle memory on pin code, Mixin messenger has the following feature:

User have to input pin code for 4–5 times when creating or modifying pin code

Remind user to select hard to guess pin instead of 123456.

Force user to input pin code if over 24 hours is passed after last time user open wallet.

Keep in mind：

Guide user to setup PIN code

No body can help you recover pin code. That’s the part of security design. So help user has a solid memory on pin code.

There is anti-theft solution in server, user’s request will be blocked for 24 hours if user input wrong pin code for over 5 times in a day.

Of course you can deploy secure finger print payment. You can search Secure Enclave for iOS device, isInsideSecureHardware for Android device. You can also read code of Mixin messenger.

6-Read assets

API：https://developers.mixin.one/api#apiread_assets and https://developers.mixin.one/api#apiread_asset

Mixin messenger will show the logo of token if Mixin team has verified the asset. This is a solution to resolve the same name token issue. If a token owner want to show the logo in Mixin messenger, owner need to submit project information to https://coinmarketcap.com, and go to our repo to create pull request https://github.com/MixinNetwork/asset-profile

All blockchain asset list will be returned even if user did not has any asset at all. If an asset is not found in the user’s asset, that means the user don’t have such an asset. It will be found after user deposit or received asset from others.

7-Deposit

https://developers.mixin.one/api#apiread_assets will return the deposit address for asset, you need to read it again if the address is not returned https://developers.mixin.one/api#apiread_asset

The deposit address is the same for the same public Blockchain, that means you can deposit OmniUSDT into BTC address and ERC20 token in ETH address

To acquire deposit address for EOS and BTS, you need to apply an account_name and an account_tag(memo), you need apply public key for other assets. You need all three parameters to know the asset type and whether deposit address is returned.

To keep Mixin network free of double spend attacks, Mixin network need more confirmation than other wallets and exchanges. Developer can know confirmations of one specific blockchain from mixin network asset api.

Sometimes you may meet unexpected delay after deposit or withdraw asset. You can visit blockchain explorer to check synchronize status. You also can directly contact development team.

8-Transfer

API https://developers.mixin.one/api#apitransfer . Mixin network need developer generate unique trance_id for each transfer. Duplicated trace_id will be rejected by network. Some teams use the snapshot_id in response as a random generator source (Because there is no duplicated snapshot_id in Mixin network).

Mixin Messenger will generate trace_id internally in transaction page.

9-Withdraw

A withdraw address must be created before user can withdraw asset. Pin code is required to modify or delete withdraw address. There is no transaction fee and instantly confirmed if withdraw happen between two address mixin network. Transferring asset from Mixin messenger to Ocean.one(Our decentralized exchange) is free and instant confirm because they are all on mixin network.

Withdraw address is created by account_name and account_tag in EOS、BTS. Public key and label are required to create withdraw address for other assets. API https://developers.mixin.one/api#apicreate_address。

The withdraw amount must be more than the minimum amount. You can query the minimum value from this API by key “dust”. There is no minimum amount requirement if withdraw happen between Mixin network Dapps.

Some blockchain force user keep a reserve amount of asset in account so user can not withdraw all asset(XRP). Developer can get the information in the api by key “reserve”

The withdraw fee is not fixed, it is dynamically based on different factors. Developer can query the fee by key “fee”. Only a few app in Mixin network will charge withdraw fee and most of Dapp do not charge at all.

The Deposit address is different with the withdraw address. The actual withdraw address could be one or more random addresses. You can know the detail in white paper.

The withdraw fee will transfer back to developer. Detail will be confirmed in the future.

10-How to know user’s action deposit, withdraw and transfer

If you really want to know your user’s action, you have to scan the whole Mixin network snapshots. Mixin network will return user_id if the event is initiated by your user API：https://developers.mixin.one/api#apiread_snapshots

The API don’t have a feature to let developer only search developer’s user snapshots.

There is an example in OceanOne https://github.com/MixinNetwork/ocean.one/blob/master/exchange.go , PollMixinNetwork

11-Transfer asset hold by app

Click the App Id to update secure related parameter : input session id, pin token, private key

You will see asset list if you click the key icon on the right of app id will. You will be guided to update secure related parameter if these parameter are missing.

Click on single asset to manage asset UI.

To deposit asset into app account, you have to use your Mixin messenger account to transfer asset to app account. You can search Mixin id of your app inside Mixin messenger and transfer asset to the account inside chat page. You can only deposit asset into your app account.

12-Resources

Golang SDK：https://github.com/MixinNetwork/bot-api-go-client

Mixin Messager Android：https://github.com/MixinNetwork/android-app

Mixin Messager iOS：https://github.com/MixinNetwork/ios-app

Nodejs Demo （community developer）: https://github.com/virushuo/mixin-node

Python Demo（community developer）: https://github.com/myrual/mixin_client_demo

Java Demo（community developer）: https://github.com/qige-one/mixin_java_sdk

Mixin official developer group：https://mixin.one/codes/0f2a743d-d86b-4a6c-b26c-14e320799311

13-Other