Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uniibu/b6b54f3054d631569ac7d9f4e278754b to your computer and use it in GitHub Desktop.
Save uniibu/b6b54f3054d631569ac7d9f4e278754b to your computer and use it in GitHub Desktop.
Adding Monacoin to Coinomi

Usecase - Integrating Monacoin to Coinomi

A simple usecase of a Bitcoin compatible coin integration. Not all coins are created equal, so it is possible that extra work must be done to successfully integrate a new cryptocurrency.

  1. Start the Monacoin daemon and in the monacoin.conf file add the option "txindex=1"
rpcuser=monacoinrpc
rpcpassword=MFfySYp9o9qQi0mYbQmxOdE1pEHVS1DQuhhHssOzkO3
rpcport=8022

txindex=1

We start the daemon with the -datadir parameter:

monacoind -datadir=/coinomi/coind/monacoin &
  1. Use preferably this electrum server with a configuration file similar to the following. You need to find the values pubkey_address and script_address from the Monacoin source code and for the genesis_hash you can execute the rpc command: getblockhash 0.
[server]
host = 0.0.0.0
electrum_rpc_port = 2022
#report_host =
stratum_tcp_port = 5022
stratum_http_port = 4022
stratum_tcp_ssl_port =
stratum_http_ssl_port =
#report_stratum_tcp_port = 50001
#report_stratum_http_port = 80
#report_stratum_tcp_ssl_port = 50002
#report_stratum_http_ssl_port = 443
password = secret
banner = Welcome to Electrum!
#irc = no
#irc_nick = <yournickname>
#ssl_certfile = /path/to/electrum-server.crt
#ssl_keyfile = /path/to/electrum-server.key
logfile = /coinomi/logs/elect-monacoin.log

# default backend is leveldb (pruning server)
backend = leveldb

## Change the following to enable testnet
[network]
pubkey_address = 50
script_address = 5
genesis_hash = ff9f1c0116d19de7c9963845e129f9ed1bfc0b376eb54fd7afa42e0d418c8bb6

[leveldb]
#fulltree is the new UTXO tree, required for Electrum 2.0 clients
path = /coinomi/electrum/monacoin/data
# for each address, history will be pruned if it is longer than this limit
pruning_limit = 100

[bitcoind]
bitcoind_host = localhost
bitcoind_port = 8022
# user and password from bitcoin.conf
bitcoind_user = monacoinrpc
bitcoind_password = MFfySYp9o9qQi0mYbQmxOdE1pEHVS1DQuhhHssOzkO3

From the electrum folder you can start the electrum daemon like this:

./run_electrum_server --conf /coinomi/electrum/monacoin/conf.txt

NOTICE: If you get errors, check x11hash, peercoin-family, blackcoin branches for specific fixes for various coins. There is a case in some coins where the getrawtransaction does not return the coinbase (or coinstake in PoS coins) transaction of a orphaned block. One fix can be seen here. So try to observe a blockchain reorg to verify that Electrum server runs without an issue.

After the Electrum server finishes syncronizing, test it by connecting first:

nc localhost 5022

and then pasting the following:

{"id": 1, "method": "blockchain.address.get_history", "params": ["A USED ADDRESS FROM YOUR QT WALLET"]}

You should see all the past transactions of the A USED ADDRESS FROM YOUR QT WALLET address. Then paste this:

{"id": 2, "method": "blockchain.address.subscribe", "params": ["A USED ADDRESS FROM YOUR QT WALLET"]}

After you send some coins to the A USED ADDRESS FROM YOUR QT WALLET address, you should see the server replying something after some seconds.

  1. Create a new subclass of CoinType called MonacoinMain in the coinomi-android/core/coins/ path and set the correct values (the bip44Index must be registered here). Add MonacoinMain to the com.coinomi.core.coins.CoinID class.
public class MonacoinMain extends CoinType {
    private MonacoinMain() {
        id = "monacoin.main";

        addressHeader = 50;
        p2shHeader = 5;
        acceptableAddressCodes = new int[] { addressHeader, p2shHeader };
        spendableCoinbaseDepth = 100;

        family = BitFamily.get();
        name = "Monacoin";
        symbol = "MONA";
        uriScheme = "monacoin";
        bip44Index = 22;
        unitExponent = 8;
        feePerKb = value(100000);
        minNonDust = value(1000); // 0.00001 MNC mininput
        softDustLimit = value(100000); // 0.001 MONA
        softDustPolicy = SoftDustPolicy.BASE_FEE_FOR_EACH_SOFT_DUST_TXO;
    }

    private static MonacoinMain instance = new MonacoinMain();
    public static synchronized MonacoinMain get() {
        return instance;
    }
}
  1. Create a new flat-style icon that harmonically matches the existing icon set

  2. Add this coin to the com.coinomi.wallet.Constants class (check the DEFAULT_COINS_SERVERS, COINS_ICONS, SUPPORTED_COINS)

After you compile the android app the coin will appear in the list of the new coins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment