Skip to content

Examples

KalinkinaMaria edited this page Feb 25, 2019 · 4 revisions

Generate Metahash address

> python crypt_example_bin.py generate
Start generate MetaHash address...
Step 1. Generate private and public keys. Take part of the public key that equals to 65 bytes.
Step 2. Perform SHA-256 hash on the public key.
Done
Step 3. Perform RIPEMD-160 hash on the result of previous step.
Done
Step 4. SHA-256 hash is calculated on the result of previous step.
Done
Step 5. Another SHA-256 hash performed on value from Step 4.  Save first 4 bytes.
Done
Step 6. These 4 bytes from last step added to RIPEMD-160 hash with prefix 0x. 
Your Metahash address is 0x003d3b27f544d1dc03d6802e6379fdcfc25e0b73272b62496b

As a result, output files will be created in your folder:

  • 0x003d3b27f544d1dc03d6802e6379fdcfc25e0b73272b62496b_private.pem - private key file
  • 0x003d3b27f544d1dc03d6802e6379fdcfc25e0b73272b62496b_public.pub - public key file
  • 0x003d3b27f544d1dc03d6802e6379fdcfc25e0b73272b62496b.txt - metahash address file

Fetch balance of Metahash wallet by address

> python crypt_example_bin.py fetch-balance --net=dev --address=0x003d3b27f544d1dc03d6802e6379fdcfc25e0b73272b62496b
{
    "id": 1,
    "result": {
        "address": "0x003d3b27f544d1dc03d6802e6379fdcfc25e0b73272b62496b",
        "received": 10000,
        "spent": 2000,
        "count_received": 1,
        "count_spent": 2,
        "block_number": 1501,
        "currentBlock": 1512
    }
}

Fetch history of Metahash wallet by address

> python crypt_example_bin.py fetch-history --net=dev --address=0x003d3b27f544d1dc03d6802e6379fdcfc25e0b73272b62496b
{
    "id": 1,
    "result": [
        {
            "from": "0x00525d3f6326549b8974ef669f8fced6153109ba60d52d547d",
            "to": "0x003d3b27f544d1dc03d6802e6379fdcfc25e0b73272b62496b",
            "value": 10000,
            "transaction": "53a14ebb8bd111a80d013d015c14a856facff40a55852ad83e2934346df18d5d",
            "timestamp": 1529306546
        },
        {
            "from": "0x003d3b27f544d1dc03d6802e6379fdcfc25e0b73272b62496b",
            "to": "0x00525d3f6326549b8974ef669f8fced6153109ba60d52d547d",
            "value": 1000,
            "transaction": "babd020d4f33bbf208a62f39e32de3a37e4a81c1cd607cd4d4bcd4e7d4bcf701",
            "timestamp": 1529306666
        },
        {
            "from": "0x003d3b27f544d1dc03d6802e6379fdcfc25e0b73272b62496b",
            "to": "0x00525d3f6326549b8974ef669f8fced6153109ba60d52d547d",
            "value": 1000,
            "transaction": "ee0e11b793ff5a5b0d6954f0da4964ceb53f9887480e9a5e42608830ed401963",
            "timestamp": 1529308272
        }
    ]
}

Get transaction information by hash

> python crypt_example_bin.py get-tx --net=dev --hash=ee0e11b793ff5a5b0d6954f0da4964ceb53f9887480e9a5e42608830ed401963
{
    "id": 1,
    "result": {
        "transaction": {
            "from": "0x003d3b27f544d1dc03d6802e6379fdcfc25e0b73272b62496b",
            "to": "0x00525d3f6326549b8974ef669f8fced6153109ba60d52d547d",
            "value": 1000,
            "transaction": "ee0e11b793ff5a5b0d6954f0da4964ceb53f9887480e9a5e42608830ed401963",
            "timestamp": 1529308272
        }
    }
}

Create transaction...

...without data

> python crypt_example_bin.py create-tx --to=0x00525d3f6326549b8974ef669f8fced6153109ba60d52d547d --value=1000 --nonce=3 --privkey=mh_private.pem
{
    "jsonrpc": "2.0",
    "method": "mhc_send",
    "params": {
        "to": "0x00525d3f6326549b8974ef669f8fced6153109ba60d52d547d",
        "value": "1000",
        "fee": "",
        "nonce": "3",
        "data": "",
        "pubkey": "3056301006072a8648ce3d020106052b8104000a034200042fe59a96a81e55a592f5deedc331218f865a707e78254e2e5b476aa81e6dba17da86010a36a952c71d839dcdb9e20fbb5d29e7a739ee61444fe008d35c7557e8",
        "sign": "3046022100c3a396b901bc856063a86c031edbd12de4ac3d8a47d4f447417b787eb6935845022100f0d5def340f8265f390bd025afcc36bb50523a5ec2e75a77ca38dbeaf6735d34"
    }
}

...with data

For sending data will be charged a fee equal to the data field length. For example, if data="qwerty", then fee=6.

> python crypt_example_bin.py create-tx --data="qwerty" --to=0x00525d3f6326549b8974ef669f8fced6153109ba60d52d547d --value=1000 --nonce=3 --privkey=mh_private.pem
{
    "jsonrpc": "2.0",
    "method": "mhc_send",
    "params": {
        "to": "0x00525d3f6326549b8974ef669f8fced6153109ba60d52d547d",
        "value": "1000",
        "fee": "6",
        "nonce": "3",
        "data": "717765727479",
        "pubkey": "3056301006072a8648ce3d020106052b8104000a034200042fe59a96a81e55a592f5deedc331218f865a707e78254e2e5b476aa81e6dba17da86010a36a952c71d839dcdb9e20fbb5d29e7a739ee61444fe008d35c7557e8",
        "sign": "30440220085be5094e855d897ed4c834eb42cc992927a5b45de88ba6ad6822e7d791602c02200cfe0cd4c9fdb855a8a363edd5d80e30ef1c1dc736e8588c0892724c598b1b1d"
    }
}

Send transaction...

As a result, we get a transaction hash in "params".

...without data

> python crypt_example_bin.py send-tx --net=dev --to=0x00525d3f6326549b8974ef669f8fced6153109ba60d52d547d --value=1000 --privkey=mh_private.pem
{
    "result": "ok",
    "params": "863b08cce1f6936645065cc0da050ed0028291af70516bccdb5eec6ad0cef0d5"
}

...with data

> python crypt_example_bin.py send-tx --net=dev --data="qwerty" --to=0x00525d3f6326549b8974ef669f8fced6153109ba60d52d547d --value=1000 --privkey=mh_private.pem
{
    "result": "ok",
    "params": "e5147c8c42c94344a067fe2ded493f15cc8e4299b3333f6651ecd3e6381bfefa"
}