-
Notifications
You must be signed in to change notification settings - Fork 1
#103_Multichain_API
Ahmad Bin Amzah – 01/05/2019
- Select the best language to use in an API
- Deploying data stream with an API
- Multichain Documentation
- Forums
Multichain offers a JSON-RPC API that can be used to access and manage the blockchain remotely. There are several different methods to access and execute Multichain API calls. One of them involves using third-party libraries which provides convenient wrappers that enable applications to interact with Multichain. However, there are methods that do not require the use of third-party libraries.
Multichain API calls can be sent via a POST request to the Multichain Blockchain which needs be done by any language that supports HTTP basic authentication. There are several requirements to use this method;
- Acquire the IP address of the node instance and the RPC port which is obtained via running the command
multichain-cli [chain-name] getblockchainparamsunder "default-rpc-port". - Acquire the RPC username and password obtained by reading the file
multichain.confin the~/.multichain/[chain-name]/directory. - Allow RPC connections by adding the
rpcallowip=setting to themultichain.confand specifying the IP addresses permitted to make RPC connections to Multichain. Although it is advised not to use "0.0.0.0/0" to allow any address to make connections, for the purposes of testing, this can make it easier seeing as we are working on a prototype. - After specifying the allowed IP addresses, the node needs to restart. Simply execute the following commands;
multichain-cli [chain_name] stop,multichaind [chain_name] -daemon
After fulfilling the requirements, HTTP basic authentication with the RPC username and password to the appropiate IP address and RPC port could be used with an API to send JSON which will execute Multichain JSON-RPC calls listed here. JSON would be stored in the POST body in the format;
{"method":"create","params":["stream1","false"],"id":123,"chain_name":"chain1"}This is the same as using the command-line to execute the API command multichain-cli chain1 create stream1 false, which will create a stream to the blockchain named "stream1".
- Using Postman to test and create POST requests, JSON could be sent to the RPC port (6836) and IP address of the node instance (43.240.97.10). The URL used would be
http://43.240.97.10:6836/. - An Authorization header would be generated by specifying the authorization type with Basic Authentication, entering the username (multichainrpc) and password obtained via
multichain.conf. - The Content-Type header is used to specify the type of data stored in the body, which is JSON.
- Within the body, the following JSON data is stored to execute an API call which will retrieve information about "stream1";
{"method":"getstreaminfo","params":["stream1"],"id":"123","chain_name":"chain1"}- HTTP request:
POST / HTTP/1.1
Host: 43.240.97.10:6836
Content-Type: application/json
Authorization: Basic bXVsdGljaGFpbnJwYzpCU1lYa2dVOVRMWG9oMndzTnM1Q1JqODRiQzl1bmZ1QWZzNktDSkxZaEo5bw==
cache-control: no-cache
Postman-Token: db128892-1e9b-46fb-8cd3-28d06cae06c7
{"method":"getstreaminfo","params":["stream1"],"id":"123","chain_name":"chain1"}- After sending the request, the HTTP response will return information about "stream1" within the message body as JSON data;
{
"result": {
"name": "stream1",
"createtxid": "96041222c6d24fcf451aea905bcdfc1287d5238069284bef5e36f1af970e624f",
"streamref": "7-264-1174",
"restrict": {
"write": true,
"onchain": false,
"offchain": false
},
"details": {}
},
"error": null,
"id": "123"
}About
Documents
-
AWS
-
Other
-
REST
-
Nectar
-
Rancher
-
ASP.NET
-
Data
-
Blockchains
-
Processes