Guidance of Hydra Deployment and RPC Settings
This guidance includes how to deploy, run and make RPC calls.
Suppose the readers are able to use Linux,Mac or Windows command line. If you are not familiar with command line, or just interested in using GUI wallet, please refer to another document about hydra Wallet Tutorial.

Get hydra Node

There are at least 4 ways to get a hydra node, you can choose any way:
1. Download the binaries
If you do not care much about hydra's source code, the easiest way to obtain hydra node is to download the latest binaries on the hydra release page. Currently it supports Linux, Window, OSX. It is highly recommended to download the latest version. In this guidance, we will use v0.14.13 version as an example。
(Note: the version number you see might be different, here is v0.14.13, but other key words except for version are the same.)
    For Mac user:-0.18.5.5-osx64.tar.gz
    For Linux users: hydra-0.18.5.5-i686-pc-linux-gnu.tar.gz(32bit) orhydra-0.18.5.5-x86_64-linux-gnu.tar.gz(64bit)
    For Windows users:hydra-0.18.5.5-win32.zip(32bit) or hydra-0.18.5.5-win64.zip(64bit)
    For Raspberry Pihydra-0.18.5.5-arm-linux-gnueabihf.tar.gz
Decompress after downloading, then you will get hydrad and hydra-cli under the path/bin.
Please refer to https://github.com/Hydra-Chain/node/releases,Current support Ubuntu,Debian and Mint。
Raspberry Pi users can also use apt - please refer to https://github.com/Hydra-Chain/node/releases
After installation, you should be able to run hydrad and hydra-clidirectly in the terminal。
2. Compiler from source code
If you want to compile latest hydra from source code, please pull the latest source from github : https://github.com/Hydra-Chain/node
The instruction for compilation : https://github.com/Hydra-Chain/node Currently we recommend to compile on Linux or OSX, while other platforms might need more configuration.
After compilation, you also get hydrad and hydra-cli under the path/src/
3. Get Hydra node docker image
Suppose user has docker environment installed correctly. (what is docker?)
The Hydra official docker image on docker hub is locktrip/hydra-node, you can pull it by docker command :
1
docker pull locktrip/hydra-node
Copied!
docker run -d -P --name Hydra -v /src/hydra:/hydra -e TZ=Europe/Sofia -i -t -p 3338:3338 locktrip/hydra-node Make sure to set your time zone according to your locale. Startup flags can be set as well such as -staking=false to disable staking.
All the ways above can get Hydra nodes. There are two important binaries which are related to deployment and RPC calls:
hydrad:Hydra core program, i.e. Hydra fullnode program.
hydra-cliHydra command line interface,interact with hydrad, achieve RPC calls.

Deploy Hydra node

For the instruction for Hydra docker images, please refer to "How to launch Hydra with docker".
Other normal deployment methods are almost the same, here we take Ubuntu as an example. The commands in Mac and windows are exactly the same.
Run Hydra fullnode with ./hydrad
1
./hydrad -daemon
Copied!
This with launch a hydrad daemon with the option -daemon. If user are interested in the event logs about smart contract, please add one more option -logevents.
More options can be found:
1
./hydrad -help
Copied!
To stop running:
1
./hydra-cli stop
Copied!
The default data path for different platforms:
    Linux:~/.hydra
    Mac OSX:~/Library/Application Support/hydra
    Windows:%APPDATA%\hydra
You can also use -datadir to set your own data path。
hydra node will sync all the historical block data for first launch, and saves to datadir. It might take some time. Then diagnostics for the node can be found under the data path ~/.hydra/debug.log

Local RPC call

When the hydra node is running, we can use hydra command line interface hydra-cli to interact with hydrad, and make local RPC calls.
e.g.:
1
[email protected]:~/-0.hydra14.3/bin$ ./hydra-cli getinfo
2
{
3
"version": 140300,
4
"protocolversion": 70016,
5
"walletversion": 130000,
6
"balance": 0.00000000,
7
"stake": 0.00000000,
8
"blocks": 12126,
9
"timeoffset": 0,
10
"connections": 8,
11
"proxy": "",
12
"difficulty": {
13
"proof-of-work": 1.52587890625e-05,
14
"proof-of-stake": 886731.5868738915
15
},
16
"testnet": false,
17
"moneysupply": 100028504,
18
"keypoololdest": 1505186997,
19
"keypoolsize": 100,
20
"paytxfee": 0.00000000,
21
"relayfee": 0.00400000,
22
"errors": ""
23
}
Copied!
To get all RPC command list:
1
./hydra-cli help
Copied!
To get help for specific RPC command, use ./hydra-cli help,e.g.:
1
./hydra-cli help getinfo
Copied!

JsonRPC settings

You can get the jsonrpc example by using (here we use getinfo as an example): ./hydra-cli help getinfo
1
Examples:
2
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:3389/
Copied!
The example shows detailed format for jsonrpc content. However, it can only be called after setting rpcuser and rpcpassword. There are two ways to set the parameters, you can choose either.
Method 1:Create config file ~/.hydra/hydra.conf,which should include:
1
rpcuser=test #rpc user name, (necessary)
2
rpcpassword=test1234 #rpc password, (necessary)
3
rpcbind=0.0.0.0 (instructs which IP to listen for)
4
# By default, only local jsonrpc is allowed
5
# Remote connection is allowed only when setting rpcallowip as following:
6
# both ipv4 and ipv6 can be set, e.g.:
7
#rpcallowip=192.168.77.51/255.255.255.0
8
#rpcallowip=1.2.3.4/24
9
#rpcallowip=2001:db8:85a3:0:0:8a2e:370:7334/96
Copied!
For more config settings, please refer to :hydra.conf example
After creating the config file, please restart the node to finish settings.
Method 2:Restart Hydra node with following options:
1
./hydrad -daemon -rpcuser=test -rpcpassword=test1234 -rpcbind=0.0.0.0 -rpcallowip=192.168.77.51/255.255.255.0
Copied!
The meaning of options rpcuser, rpcpassword and rpcallowip are all the same with the config file above.

RPC call example

You can make remote RPC calls after the settings above. Here is an example: Suppose the hydra node is running on an Ubuntu machine, whose ip is 192.168.77.188, default port=3389. Now we try to make jsonrpc call in a remote macbook:
1
$ curl --user test:test1234 --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' -H 'content-type: text/plain;' http://192.168.77.188:3389/
2
{"result":{"version":140300,"protocolversion":70016,"walletversion":130000,"balance":0.00000000,"stake":0.00000000,"blocks":12197,"timeoffset":0,"connections":8,"proxy":"","difficulty":{"proof-of-work":1.52587890625e-05,"proof-of-stake":650787.7561123729},"testnet":false,"moneysupply":100028788,"keypoololdest":1505186997,"keypoolsize":100,"paytxfee":0.00000000,"relayfee":0.00400000,"errors":""},"error":null,"id":"curltest"}
Copied!
The result is identical with local call.
You can also use tools like postman to get the same result:
postman

Nginx settings(optional)

As the example above, you might find that it is quite complicated to make remote jsonrpc, since you must include rpcuser, rpcpassword, as well as port in the command. If you don't want users to provide these parameters, we recommand using Nginx. The benefits for Nginx is not only about simplification, but also a good way to hide rpcuser, rpcpassword and port number. And you can filter some RPCs for security. Here we suppose the reader have installed Nginx and have basic knowledges about how to use it.
example:
    hydra node is running on 192.168.77.188,
    api proxy ip 192.168.77.51, with Nginx installed
Instructions:
1.Set the hydra.conf of hydra node, remember to add the proxy ip to rpcallowip e.g.:
1
rpcuser=test
2
rpcpassword=test1234
3
rpcallowip=192.168.77.51/255.255.255.0
Copied!
2.Setup Nginx :
1
server {
2
listen 80;
3
server_name localhost;
4
5
location / {
6
proxy_pass http://192.168.77.188:3389; #to port 3389
7
proxy_set_header Authorization "Basic dGVzdDp0ZXN0MTIzNA=="; # its the base64 encode of test:test1234
8
}
9
}
Copied!
3.Then you can make remote rpc call through proxy, without rpcuser or rpcpassword. e.g.:
1
$ curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' -H 'content-type: text/plain;' http://192.168.77.51/
2
{"result":{"version":140300,"protocolversion":70016,"walletversion":130000,"balance":0.00000000,"stake":0.00000000,"blocks":12250,"timeoffset":0,"connections":8,"proxy":"","difficulty":{"proof-of-work":1.52587890625e-05,"proof-of-stake":651324.7815933984},"testnet":false,"moneysupply":100029000,"keypoololdest":1505186997,"keypoolsize":100,"paytxfee":0.00000000,"relayfee":0.00400000,"errors":""},"error":null,"id":"curltest"}
Copied!
This is only a simple example. You might have different settings or tools instead.

Executing common commands through RPC (create wallet,transfer amount and get balance)

CREATEWALLET

Creates and loads a new wallet.
Arguments:
1
1. "wallet_name" (string, required) The name for the new wallet. If this is a path, the wallet will be created at the path location.
2
2. disable_private_keys (boolean, optional, default: false) Disable the possibility of private keys (only watchonlys are possible in this mode).
Copied!
Result:
1
{
2
"name" : <wallet_name>, (string) The wallet name if created successfully. If the wallet was created using a full path, the wallet_name will be the full path.
3
"warning" : <warning>, (string) Warning message if wallet was not loaded cleanly.
4
}
Copied!
Examples:
1
> hydra-cli createwallet "testwallet"
2
3
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "createwallet", "params": ["testwallet"] }' -H 'content-type: text/plain;' http://127.0.0.1:3389/
Copied!
Test example:
1
createwallet “hydra”
Copied!
Test result:
1
{
2
"name": "hydra",
3
"warning": ""
4
}
Copied!

TRANSFER AMOUNT

Send an amount to a given address.
Requires wallet passphrase to be set with walletpassphrase call.
Arguments:
1
1. "address" (string, required) The Hydra address to send to.
2
2. "amount" (numeric or string, required) The amount in HYDRA to send. eg 0.1
3
3. "comment" (string, optional) A comment used to store what the transaction is for.
4
This is not part of the transaction, just kept in your wallet.
5
4. "comment_to" (string, optional) A comment to store the name of the person or organization
6
to which you're sending the transaction. This is not part of the
7
transaction, just kept in your wallet.
8
5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.
9
The recipient will receive less hydras than you enter in the amount field.
10
6. replaceable (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees via BIP 125
11
7. conf_target (numeric, optional) Confirmation target (in blocks)
12
8. "estimate_mode" (string, optional, default=UNSET) The fee estimate mode, must be one of:
13
"UNSET"
14
"ECONOMICAL"
15
"CONSERVATIVE"
16
9. "senderaddress" (string, optional) The quantum address that will be used to send money from.
17
10."changeToSender" (bool, optional, default=false) Return the change to the sender.
Copied!
Result:
1
"txid" (string) The transaction id.
Copied!
Examples:
1
> hydra-cli sendtoaddress "HASUX9pYyHxyxMZgcS8VKBjdcQH7DAL9eW" 0.1
2
3
> hydra-cli sendtoaddress "HASUX9pYyHxyxMZgcS8VKBjdcQH7DAL9eW" 0.1 "donation" "seans outpost"
4
5
> hydra-cli sendtoaddress "HASUX9pYyHxyxMZgcS8VKBjdcQH7DAL9eW" 0.1 "" "" true
6
7
> hy-cli sendtoaddress "HASUX9pYyHxyxMZgcS8VKBjdcQH7DAL9eW", 0.1, "donation", "seans outpost", false, null, null, "", "HASUX9pYyHxyxMZgcS8VKBjdcQH7DAL9eW", true
8
9
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendtoaddress", "params": ["HASUX9pYyHxyxMZgcS8VKBjdcQH7DAL9eW", 0.1, "donation", "seans outpost"] }' -H 'content-type: text/plain;' http://127.0.0.1:3389/
10
11
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendtoaddress", "params": ["HASUX9pYyHxyxMZgcS8VKBjdcQH7DAL9eW", 0.1, "donation", "seans outpost", false, null, null, "", "HASUX9pYyHxyxMZgcS8VKBjdcQH7DAL9eW", true] }' -H 'content-type: text/plain;' http://127.0.0.1:3389/wallet/walletname
Copied!

GETBALANCE

Returns the total available balance. The available balance is what the wallet considers currently spendable, and is thus affected by options which limit spendability such as -spendzeroconfchange.
Arguments:
1
1. (dummy) (string, optional) Remains for backward compatibility. Must be excluded or set to "*".
2
2. minconf (numeric, optional, default=0) Only include transactions confirmed at least this many times.
3
3. include_watchonly (bool, optional, default=false) Also include balance in watch-only addresses (see 'importaddress')
Copied!
Result:
1
amount (numeric) The total amount in HYDRA received for this account.
Copied!
Examples:
As a json RPC call:
1
curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getbalance", "params": ["*", 6] }' -H 'content-type: text/plain;' http://127.0.0.1:3389/wallet/walletname
Copied!
Test example:
1
./hydra-cli getbalance
Copied!
Test result:
1
5.683000
Copied!
If you have any questions during node deployment and RPC calls, here are some useful documents to refer to:
    For source code compilation issues:
    Command to check all hydrad options:./hydrad -help
    Command to get all RPC list: ./hydra-cli help
    Get RPC help(like getinfo): ./hydra-cli help getinfo
    hydra.conf file example:hydra.conf
Last modified 4mo ago