multichain v1.0.0 Multichain

This library is a thin wrapper for Multichain JSON RPC. Instead of manually craft HTTP call with all params, we can put the param in config and call one function as interface to all Multichain api.

Everything in this module represent lowest Multichain API. Any Multichain API which didn’t take any argument can be called directly with format Multichain.<method_name>/0.

How to use

  1. Add dependency In your mix.exs:

        defp deps do
          [
            {:multichain, "~> 0.0.1"}
          ]
        end
  2. Add config Add your node information to your config.exs:

    config :multichain,
      protocol: "http",
      port: "1234",
      host: "127.0.0.1",
      username: "multichainrpc",
      password: "xxxxxxxxxxxxxxx",
      chain: "chain1"
  3. Done. You can now call any multichain api using api/2

    For example you want to call getinfo api, you only need to create Map and pass to the function.

    iex(1)> param = %{method: "getinfo", params: []}
    %{method: "getinfo", params: []}
    iex>(2)> Multichain.api(param)
    {:ok,
    %{
     "error" => nil,
     "id" => nil,
     "result" => %{
       "balance" => 0.0,
       "blocks" => 1001,
       "burnaddress" => "1XXXXXXWjEXXXXXXxiXXXXXXMvXXXXXXUd2fZG",
       "chainname" => "getchain",
       "connections" => 0,
       "description" => "MultiChain awesome",
       "difficulty" => 6.0e-8,
       "errors" => "",
       "incomingpaused" => false,
       "keypoololdest" => 1526642153,
       "keypoolsize" => 2,
       "miningpaused" => false,
       "nodeaddress" => "getchain@188.177.166.55.:1234",
       "nodeversion" => 10004901,
       "paytxfee" => 0.0,
       "port" => 9243,
       "protocol" => "multichain",
       "protocolversion" => 10010,
       "proxy" => "",
       "reindex" => false,
       "relayfee" => 0.0,
       "setupblocks" => 60,
       "testnet" => false,
       "timeoffset" => 0,
       "version" => "1.0.4",
       "walletdbversion" => 2,
       "walletversion" => 60000
     }
    }} 

    The full api and params you need to pass can be found on official Multichain API Documentation. Basically you put the method name

Link to this section Summary

Functions

This function will return list of all address own by the Node’s wallet including each asset list

This is the function where you can call all individual Multichain API. Only pass the method name as String and params as List

This function will return spesific balance. It will always return number

This function will return spesific balance. It will return tuple with atom and result

This function will return list of balance. If not found will return empty list

This function will return information about the connected Multichain’s node

This function will return configuration of run time parameter of the multichain

Get the list of Multichain api

This function will return list of all asset own by the node’s wallet where is_mine is true

Link to this section Functions

This function will return list of all address own by the Node’s wallet including each asset list.

iex(1)> Multichain.allbalances
{:ok,
 %{
   "1MRUjzje91QBpnBqkhAdrnCDKHikXFhsPQ4rA2" => [
     %{"assetref" => "6196-266-29085", "name" => "MMKP", "qty" => 9.0e7},
     %{"assetref" => "176-266-23437", "name" => "MMK", "qty" => 1.74e5},
     %{"assetref" => "60-266-6738", "name" => "GET", "qty" => 9970.0}
   ],
   "total" => [
     %{"assetref" => "6196-266-29085", "name" => "MMKP", "qty" => 9.0e7},
     %{"assetref" => "176-266-23437", "name" => "MMK", "qty" => 1.74e5},
     %{"assetref" => "60-266-6738", "name" => "GET", "qty" => 9970.0}
   ]
 }}
Link to this function api(method, params)

This is the function where you can call all individual Multichain API. Only pass the method name as String and params as List.

Some of example can be seen below:

Multichain.api("listaddresses", ["*", true, 3, -3])

Multichain.api("getinfo", [])

Multichain.api("help", [])
iex(1)> Multichain.api("validateaddress", ["1KFjut7GpLN2DSvRrh6UATxYxy5nxYaY7EGhys"])
{:ok,
 %{
   "error" => nil,
   "id" => nil,
   "result" => %{
     "account" => "",
     "address" => "1KFjut7GpLN2DSvRrh6UATxYxy5nxYaY7EGhys",
     "ismine" => false,
     "isscript" => false,
     "isvalid" => true,
     "iswatchonly" => true,
     "synchronized" => false
   }
 }}
Link to this function balance(address, assetcode)

This function will return spesific balance. It will always return number.

Any other problem such as wrong address and even connection problem will be translated to zero (0).

iex(1)> Multichain.balance("1DEd7MqSxLgpDs9uUipcmfXqWxxpzwiJ8SojmY", "176-266-23437")
1.0e3
Link to this function balance!(address, assetcode)

This function will return spesific balance. It will return tuple with atom and result.

While balance/2 will always return number, balance!/2 will tell you if error happened.

iex(1)> Multichain.balance!("1DEd7MqSxLgpDs9uUipcmfXqWxxpzwiJ8SojcmY", "176-266-23437")
{:error,
"Error code: 500. Reason: Invalid address: 1DEd7MqSxLgpDs9uUipcmfXqWxxpzwiJ8SojcmY"
iex(2)> Multichain.balance!("1DEd7MqSxLgpDs9uUipcmfXqWxxpzwiJ8SojmY", "176-266-23437")
{:ok, 1.0e3}  
Link to this function balances(address)

This function will return list of balance. If not found will return empty list.

iex(1)> Multichain.balance("1DEd7MqSxLgpDs9uUipcmfXqWxxpzwiJ8SojmY")
{:ok,
   %{
     "error" => nil,
     "id" => nil,
     "result" => [
       %{"assetref" => "176-266-23437", "name" => "MMK", "qty" => 1.0e3}
     ]
   }}

This function will return information about the connected Multichain’s node.

Usually this is used to check the connection.

Link to this function getruntimeparams()

This function will return configuration of run time parameter of the multichain.

Get the list of Multichain api.

This function will return list of all asset own by the node’s wallet where is_mine is true.

iex(1)> Multichain.nodebalance
{:ok,
 [
   %{"assetref" => "6196-266-29085", "name" => "MMKP", "qty" => 9.0e7},
   %{"assetref" => "176-266-23437", "name" => "MMK", "qty" => 1.74e5},
   %{"assetref" => "60-266-6738", "name" => "GET", "qty" => 9970.0}
 ]}