Skip to content
ChMarina edited this page Mar 12, 2019 · 47 revisions

API List

API Reference

generate

It generates wallet in the network where MHC client runs.

Parameters

none

Returns

address - wallet

pub_key - wallet public key

prv_key - wallet private key

Besides, 2 files are created in the folder: /opt/mhp/wallet.main/ (main means that the network runs in the main network. There are several types of networks: main|dev|v8) with the name of a created wallet and prv and pub extensions for private and public keys, respectively.

Example

// Request
curl -s -X POST --data '{"id":1, "version":"1.0.0", "method":"generate"}' 0.0.0.0:9999

// Result
{
  "jsonrpc":"2.0",
  "id":1,
  "result": 
  {
    "address":"0x002382e6e78e4f97ee636ba6ff42e80a34c076c118cb288e3c",
    "pub_key":"30563...d0af",
    "prv_key":"307402...ed0af"
  }
}

// And files:
/opt/mhp/wallet.main/0x002382e6e78e4f97ee636ba6ff42e80a34c076c118cb288e3c.raw.prv
/opt/mhp/wallet.main/0x002382e6e78e4f97ee636ba6ff42e80a34c076c118cb288e3c.raw.pub

fetch-balance

It returns current balance for the specified in the request address in the network where MHC client runs.

Parameters

address - wallet address in HEX format.

Returns

address - wallet

received - amount received

spent - amount spent

count_received - number of receipts

count_spent":0 - number of sendings

block_number - number of block where the last balance change was made

currentBlock - number of blocks in the blockchain currently

Example

// Request
curl -s -X POST --data '{"id":1, "version":"1.0.0", "method":"fetch-balance", "params": {"address":"0x002382e6e78e4f97ee636ba6ff42e80a34c076c118cb288e3c"}}' 0.0.0.0:9999

// Result
{
  "jsonrpc":"2.0",
  "id":1,
  "result": 
  {
    "address":"0x002382e6e78e4f97ee636ba6ff42e80a34c076c118cb288e3c",
    "received":1000000,
    "spent":0,
    "count_received":1,
    "count_spent":0,
    "block_number":7969,
    "currentBlock":7970
  }
}

fetch-history

It returns all transaction history for the specified in the request address in the network where the MHC client runs.

Parameters

address - wallet address in HEX format.

Returns

from - address amount was transferred from

to - address amount was transferred to

value - amount of transfer

transaction - transaction hash

timestamp - date and time of the transaction in timestamp format

Example

// Request
curl -s -X POST --data '{"id":1, "version":"1.0.0", "method":"fetch-history", "params": {"address":"0x002382e6e78e4f97ee636ba6ff42e80a34c076c118cb288e3c"}}' 0.0.0.0:9999

// Result
{
  "jsonrpc":"2.0",
  "id":1,
  "result":
  [
    {
      "from":"0x002382e6e78e4f97ee636ba6ff42e80a34c076c118cb288e3c",
      "to":"0x0004cd0ecb06e091efd2fc486d13c94eafd422486d0d3fc80c",
      "value":1,
      "transaction":"27857e9bf3e00c35cbfb0d09870250af7585dfdf7b946265e97c8c5f244beaa5",
      "timestamp":1545308555
    }, 
    {
      "from":"0x0059147ce71de3f3e74c74b6f8e4135cbec80ee3ec2f52914a",
      "to":"0x002382e6e78e4f97ee636ba6ff42e80a34c076c118cb288e3c",
      "value":1000000,
      "transaction":"4ccac941fc83edced9514969ed86925f60d618d2cd773789b01790935e2a08b5",
      "timestamp":1545306639
    }
  ]
}

create-tx

Method for creating transactions.

Parameters

address - sender wallet address in HEX format

to - recipient wallet address in HEX format

value - amount of transfer

nonce - number of outgoing transactions from the address at the time of this transaction, i.e. = count_spent + 1

Returns

transaction - transaction hash

to - recipient wallet address in HEX format

value - amount of transfer

fee - fee rate

nonce - number of outgoing transactions from the address at the time of this transaction

data - transaction-related data in HEX format

pubkey - sender public key

sign - generated transaction signature

To find out more about creating and sending transactions read the article.

Example

// Request
curl -s -X POST --data '{"id":1, "version":"1.0.0", "method":"create-tx", "params":{"address":"0x002382e6e78e4f97ee636ba6ff42e80a34c076c118cb288e3c", "to":"0x0004cd0ecb06e091efd2fc486d13c94eafd422486d0d3fc80c","value":1, "nonce":1}}' 0.0.0.0:9999

// Result
{
  "jsonrpc":"2.0",
  "id":1,
  "method":"mhc_send",
  "params":
  {
    "transaction":"0004cd0ecb06e091efd2fc486d13c94eafd422486d0d3fc80c01000100",
    "to":"0x0004cd0ecb06e091efd2fc486d13c94eafd422486d0d3fc80c",
    "value":"1",
    "fee":"",
    "nonce":"1",
    "data":"",
    "pubkey":"30563...1ed0af",
    "sign":"304502...adf804"
  }
}

send-tx

Method for sending transactions.

Parameters

address - sender wallet address in HEX format

to - recipient wallet address in HEX format

value - amount of transfer

nonce - (optional) number of outgoing transactions from the address at the time of this transaction, i.e. = count_spent + 1

Returns

result - transaction hash

To find out more about creating and sending transactions read the article.

Example

// Request
curl -s -X POST --data '{"id":1, "version":"1.0.0", "method":"send-tx", "params":{"address":"0x002382e6e78e4f97ee636ba6ff42e80a34c076c118cb288e3c", "to":"0x0004cd0ecb06e091efd2fc486d13c94eafd422486d0d3fc80c","value":1, "nonce":1}}' 0.0.0.0:9999

// Result
{"jsonrpc":"2.0","id":1,"result":"27857e9bf3e00c35cbfb0d09870250af7585dfdf7b946265e97c8c5f244beaa5"}

get-block-by-hash

View info on a specified blockchain block by its hash.

Parameters

hash - block hash

type - type of requested info: 2 - full block dump, 1 - only hashes, 0 or there isn’t - only block name.

Returns

hash - block hash

prev_hash - hash of the previous block

tx_hash - transaction hash

number - block number

timestamp - time the block that created in timestamp format

size - block size

fileName - name of the file containing info on the block.

Example

// Request
curl -s -X POST --data '{"id":1, "version":"1.0.0", "method":"get-block-by-hash", "params":{"hash":"1172121c30fa86757a193170966903ef7a3dbb9dcdbad906040730f90465fb82", "type":0}}' 0.0.0.0:9999

// Result
{
  "jsonrpc":"2.0",
  "id":1,
  "result":
  {
    "hash":"1172121c30fa86757a193170966903ef7a3dbb9dcdbad906040730f90465fb82",
    "prev_hash":"5d21042bc72ccdef03e27881375668abb3be33579714db3dfec101eba1521646",
    "tx_hash":"45df25ee86ae2245bde6bdc05e5b9910e45518b8825e361f5848ceae5bbd66a6",
    "number":7907,
    "timestamp":1545252302,
    "size":275,
    "fileName":"/data/metahash/20181219.blk"
  }
}

get-block-by-number

View info on a specified blockchain block by its number.

Parameters

number - block number

type - type of requested info: 2 - full block dump, 1 - only hashes, 0 or there isn’t - only block name.

Returns

hash - block hash

prev_hash - hash of the previous block

tx_hash - transaction hash

number - block number

timestamp - time the block that created in timestamp format

size - block size

fileName - name of the file containing info on the block.

Example

// Request
curl -s -X POST --data '{"id":1, "version":"1.0.0", "method":"get-block-by-number", "params":{"number":7907, "type":0}}' 0.0.0.0:9999

// Result
{
  "jsonrpc":"2.0",
  "id":1,
  "result":
  {
    "hash":"1172121c30fa86757a193170966903ef7a3dbb9dcdbad906040730f90465fb82",
    "prev_hash":"5d21042bc72ccdef03e27881375668abb3be33579714db3dfec101eba1521646",
    "tx_hash":"45df25ee86ae2245bde6bdc05e5b9910e45518b8825e361f5848ceae5bbd66a6",
    "number":7907,
    "timestamp":1545252302,
    "size":275,
    "fileName":"/data/metahash/20181219.blk"
  }
}

get-count-blocks

Getting info on the total number of blocks in the blockchain (the length of the chain of blocks)

Parameters

none

Returns

count_blocks - number of blocks of the blockchain

Example

// Request
curl -s -X POST --data '{"id":1, "version":"1.0.0", "method":"get-count-blocks"}' 0.0.0.0:9999

// Result
{
  "jsonrpc":"2.0",
  "id":1,
  "result":
  {
    "count_blocks":7907
  }
}

get-dump-block-by-hash

Получить дамп блока по его хэшу.

Parameters

hash - block hash

Returns

dump - дамп блока

Example

// Request
curl -s -X POST --data '{"id":1, "version":"1.0.0", "method":"get-dump-block-by-hash", "params":{"hash":"1172121c30fa86757a193170966903ef7a3dbb9dcdbad906040730f90465fb82"}}' 0.0.0.0:9999

// Result
{"jsonrpc":"2.0","id":1,"result":{"dump":"0123456789abcdefcead1a5c000000005d21042bc72ccdef03e27881375668abb3be33579714db3dfec101eba152164645df25ee86ae2245bde6bdc05e5b9910e45518b8825e361f5848ceae5bbd66a6c1001e954698a8d7d32d491866c19e4ceaab3458696492e96d670100fa6c0900483046022100f443ae752e606fa162dfffc66e7a03788deb38d9c5ba56111bb6a93665de46440221008afa421023f9d93e3037ca3dced2288ba89c62c67875e832a79925e82ab46bb2583056301006072a8648ce3d020106052b8104000a034200047f2c35bdb88d6a1d778322c0604d3dd96eaf83e624f4bd4bbe0aa0d5d84f955e88023886c49294fa6eb080043755e5f895746c1afa3f47e277c30bb9ba013a6d00"}}

get-dump-block-by-number

Получить дамп блока по его номеру.

Parameters

number - block number

Returns

dump - дамп блока

Example

// Request
curl -s -X POST --data '{"id":1, "version":"1.0.0", "method":"get-dump-block-by-number", "params":{"number":7907}}' 0.0.0.0:9999

// Result
{"jsonrpc":"2.0","id":1,"result":{"dump":"0123456789abcdefcead1a5c000000005d21042bc72ccdef03e27881375668abb3be33579714db3dfec101eba152164645df25ee86ae2245bde6bdc05e5b9910e45518b8825e361f5848ceae5bbd66a6c1001e954698a8d7d32d491866c19e4ceaab3458696492e96d670100fa6c0900483046022100f443ae752e606fa162dfffc66e7a03788deb38d9c5ba56111bb6a93665de46440221008afa421023f9d93e3037ca3dced2288ba89c62c67875e832a79925e82ab46bb2583056301006072a8648ce3d020106052b8104000a034200047f2c35bdb88d6a1d778322c0604d3dd96eaf83e624f4bd4bbe0aa0d5d84f955e88023886c49294fa6eb080043755e5f895746c1afa3f47e277c30bb9ba013a6d00"}}

get-tx

Просмотр информации о транзакции

Parameters

hash - transaction hash

Returns

Example

// Request
curl -s -X POST --data '{"id":1, "version":"1.0.0", "method":"get-tx", "params":{"hash":"27857e9bf3e00c35cbfb0d09870250af7585dfdf7b946265e97c8c5f244beaa5"}}' 0.0.0.0:9999

// Result
{
  "jsonrpc":"2.0",
  "id":1,
  "result":
  {
    "transaction":
    {
      "from":"0x002382e6e78e4f97ee636ba6ff42e80a34c076c118cb288e3c",
      "to":"0x0004cd0ecb06e091efd2fc486d13c94eafd422486d0d3fc80c",
      "value":1,
      "transaction":"27857e9bf3e00c35cbfb0d09870250af7585dfdf7b946265e97c8c5f244beaa5",
      "data":"",
      "timestamp":1545308555,
      "type":"block",
      "blockNumber":7972,
      "signature":"3044022076...2bad167d93b",
      "publickey":"3056301006072a86...c9ba98268c33c329bd59781ed0af",
      "fee":0,
      "realFee":0,
      "nonce":1,
      "status":"ok"
    },
    "countBlocks":141069,
    "knownBlocks":141069
  }
}
Clone this wiki locally