Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
This branch is 3 commits ahead of LimeChain:master.

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Token Migration Overview

Around 2nd of September 2019, all ERC 20 Aeternity tokens will be frozen. All ethereum holders need to be able to migrate their tokens to the mainnet after the Lima hardfork. We will provide an easy to use solution to help the community to migrate safely their tokens to the new network.

This solution will consist of several parts - migrator web-app, migration back-end app, and aeternity smart contract. The general idea is to allow the ethereum users to sign a message (their aeternity address) with their private key and send it to an Aeternity smart contract. The Aeternity smart contract will recover the ethereum address of the signer and check whether this is a user that has a balance on the ethereum mainnet. If this is proven to be an ethereum AE holder, the smart contract will disburse the exact number of AE to the users AE address in the Aeternity network.

Obviously, an aeternity smart contract cannot reach to the ethereum network. In order for the smart contract to check the balance, a list of all ethereum AE holder balances needs to be available. The sheer number of ethereum AE holders (20000+) makes the storing of such a list in the smart contract unfeasible. To solve this problem we will introduce Merkle tree-based solution.

A backend app is going to create and maintain a Merkle tree of all ethereum AE holders and their balances. The merkle tree root hash will be stored in the Aeternity smart contract and through the use of hashing (and some additional data - index and intermediary hashes), the Aeternity smart contract will be able to check the validity of the migration claim by a given user. This back-end app will be open-source and can be run by everyone in multiple instances to ensure decentralization.


To begin the migration the users must provide their aeternity accounts. If they lack one, ability to create will be present. After that, the users must authenticate with their Etherum address. There are two ways of achieving that - with Metamask or MyEtherWallet. The first phase will support only Metamask. After the authentication, the balance that will be migrated will be shown and they will be prompt to sign a message with their ethereum private key. The message must be their aeternity account! Once the message is signed, the client-side will build a transaction for the token migration. The raw transaction will be sent to the backend. On the other hand, the backend will have the ability to sign and send the transaction. The backend will have several functions, create and store the merkle tree information, send the necessary information to the client-side and send the transactions. The merkle tree approach was chosen because it is far more cheap to use than storing all ethereum addresses and balances into a smart contract. From all addresses and balance, the backend will create the merkle tree and store the hashes into a Postgre database. The smart contract will serve as a proof and migrate the tokens.


The backend will be used to join needed data(amount of tokens, merkle tree leaf index and an array of intermediary hashes) from provided user ethereum address, AE address and signature(signed AE address). With this data, backend would create contract call tx, sign it with internal wallet and broadcast it. If smart contract accepts(verifies) current request would transfer tokens to provided AE address, emit event and would return number of transfer. After that backend would notify backendless service for current transfer and user would not be able to transfer it again.


What you should have installed

clone this repo into $GOPATH/go/src in project root directory go get // windows users: if you get this error: '"gcc": executable file not found in %PATH%' // download and install: 'TDM-GCC' is a compiler suite for Windows. // then repeat command go get or go get -u

set the environment variables in an .env file. You can see example in the .env_example file

// .env_example

CONNECTION_STRING_POSTGRESQL="user=xxxx password=xxxxx dbname=xxxxxx port=5433 sslmode=disable"
CONNECTION_STRING_POSTGRESQL_PROD="host=/cloudsql/xxxxxx:xxxxxx user=xxxxxxx password=xxxxxxxx dbname=xxxxxx sslmode=disable"









BEARER_AUTH_TOKEN="Bearer xxxxx"

and start it go run app.go

There are several routes that can be access

/ - GET tree status. returns merkle tree root hash and number of leafs, nodes.

    "status": true,
    "tree": {
        "root": "20B4C63E8063464DE5EF6CC60122AC3138F413A53CED28C641BD7867B76F52B9",
        "length": 301378

/info/{ethAddress} - GET info by given ethereum address. Returns index, hash, amount of tokens and migration status of current leaf, and if it is migrated tx hash

    "index": 17,
    "hash": "5C73535E4E3A596B439554FC5246AF5E9307AB259E6D00D131A1A9422BE352AA",
    "tokens": "896946881386313856",
    "migrated": true,
    "migrateTxHash": "th_2RWiuYoLTVorP8XCdu7yzfJAZ2eThEUwn6XtVy9W7aaU1CijxW"

/hash/{index} - GET hash by given leaf index. Returns it's hash

    "index": 1,
    "hash": "B4E1FC7C12705A751908BA6438B77342DA68BFC322E346744BA3D38D63636FEE"

/siblings/{index} - GET intermediary hashes by given leaf index. Returns array of intermediary hashes

    "status": true,
    "hashes": [

/validate - POST validate is provided data can generate same merkle root hash. Should pass ethereum address, amount of tokens, leaf index and an array of intermediary hashes. Returns object with boolean property ‘exists’ which validates if the request is valid or not.

request body:
    "ethAddress": "0x18c4a229411ec44fc0ddfc7fd02e31fc1872a6e1",
    "balance": "449437408529709982023680",
    "index": 2345,
    "hashes": [
    "status": true,
    "exists": false

/migrate - POST migrate tokens to your AE address. Should pass ethereum address(from provided eth address backend should take leaf index and an array of intermediary hashes), AE address and signature(signed AE address). Returns tx hash and tx status

request body:
	"ethPubKey": "0xedc6942e1fbbbd8d592123c16e00d8058b396bf2",
	"aeAddress": "ak_tWZrf8ehmY7CyB1JAoBmWJEeThwWnDpU4NadUdzxVSbzDgKjP",
	"signature": "0xf31ee3eaea7e4fd318d7df027a73a06d452b0e89ff5d736e017c0fb638e631051f8d1a1f2a90665ee9f6b2e16757204861a0e3ae51a5674a8ad9f7e73d864c211b"

    "txHash": "th_4nQmPEjKwke48WkdQeTUyNMuvTGdt92CEhKaJ3mKAcPjppQqM",
    "status": "ok"

/owner - POST add token owner into database, create merkle tree leaf. Should pass ethereum address and amount of tokens. Returns index and hash of leaf

request body:
	"ethAddress" : "0x4286fF605Da8490775c7C57939a54EA4597F9D18",
	"balance": "45222147440638439718912"

    "index": 0,
    "hash": "97BE23922EB76D5CAD22BEEC69F4C3B07BA1220C932674D3C7BE8F4051245967",
    "message": "Data was successfully added!"

Import token owners (db table backup)

// mac users

  1. install brew ( if you have ‘psql’ as env variable skip this step
  2. insttall ‘libpq' if you have ‘psql’ as env variable skip this step
    brew install libpq
    brew link --force libpq

// windows users // if 'psql' is not recognized in 'CMD', you should manualy set environment path

  • 'THIS PS' right click -> Properties
  • 'Advanced system settings'
  • select 'Advanced' tab ->'Environment Variables'
  • go to 'System variables' and select/click 'Path' -> EDIT
  • 'NEW' -> type/paste your path to PostgreSQL -> 'C:\Program Files\PostgreSQL\12\bin'
  • close current CMD and reopen it.
  1. Create database. If you want to use your own database skip this step
    // `localhost (url), 5432 (port), postgres (postgres user)` are defaults of postgresql instance 
    createdb -h localhost -p 5432 -U postgres DATABASE_NAME
  1. Restore database
    psql -U postgres -h -p 5432 -d DATABASE_NAME -f ./BACKUP_FILE

P.S.: backup script should try to set "usage” rights to 'cloudsqlimportexport’ user, but this user would not exists(almost sure) in your DB and you will see error messages. Table would be imported successfullly.

linux users - how to install postgreSQL on ubuntu -

  1. sudo apt-get install wget ca-certificates
  2. wget --quiet -O - | sudo apt-key add -
  3. sudo sh -c 'echo "deb lsb_release -cs-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
  4. sudo apt-get update
  5. sudo apt-get install postgresql postgresql-contrib
  6. go to '/etc/postgresql/11/main/postgresql.conf' and uncomment this line '#listen_addresses = 'localhost' # what IP address(es) to listen on;'
  • Success. You can now start the database server using:
    pg_ctlcluster 11 main start
  1. pgAdmin4 instalation

    • sudo apt update -y && sudo apt upgrade -y
    • sudo apt-get install pgadmin4 pgadmin4-apache2 -- During this setup, you will be prompted for an email address. Provide your preferred email address(username) -- provide the password you are going to use during log in -- do not forget to wrote down username and pass -- you can connect to PostgreSQL by browsing your server's IP address or domain name followed by the suffix /pgAdmin4 in the URL. (
  2. Create database // if you try to connect through pgAdmin4 interface and an error is thrown for invalid password // or you try to execute psql command createdb -h localhost -p 5432 -U postgres test and again password required or invalid // change default password

    sudo -u postgres psql template1
    ALTER USER postgres with encrypted password 'your_password';
  • After configuring the password, edit the file /etc/postgresql/11/main/pg_hba.conf to use MD5 authentication with the postgres user:
    local   all         postgres                          md5
  • restart the PostgreSQL service to initialize the new configuration
    sudo systemctl restart postgresql.service 
  • create database
    createdb -h localhost -p 5432 -U postgres test
  1. Restore database
    psql -U postgres -h -p 5432 -d test -f ./BACKUP_FILE


No description, website, or topics provided.






No releases published


No packages published


  • Go 100.0%