JSON RPC Interfaces
In order to accept incoming connections from the network you need to configure the dacnode accordingly.
As a developer, you'll want to start interacting with dacnode and the DAC Blockchain network via your own programs and not manually through the console. To aid this, dacnode has built-in support for a JSON-RPC based APIs (standard APIs). These can be exposed via HTTP, WebSockets and IPC (UNIX sockets on UNIX based platforms, and named pipes on Windows).
The IPC interface is enabled by default and exposes all the APIs supported by dacnode, whereas the HTTP and WS interfaces need to manually be enabled and only expose a subset of APIs due to security reasons. These can be turned on/off and configured as you'd expect.
JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. It defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over HTTP, or in many various message passing environments. It uses JSON (RFC 4627) as data format.
Available Modules
The JSON-RPC API is divided into the following modules based on their functional area:
- web3: Common helper utilities and cryptographic functions.
- net: Network state, listening status, and peer counts.
- eth: Core Ethereum ledger queries, transaction creation, block info, filters, logs, and EVM executions.
- admin: Local node info, peer manipulation, and HTTP/WS RPC server controls.
- debug: Advanced block and transaction EVM execution tracing.
- ethash: Mining work templates and hashrate submissions.
- miner: Miner start/stop threads, etherbase, and block gas limit targets.
- personal: Key generation, local keystore unlocks, and transaction signing.
- trace: Historical transaction tracing and call replays.
- txpool: Inspection of the local transaction memory pool (pending/queued queue).
Node Configuration
dacnode can be configured to accept RPC calls over HTTP, WebSocket and IPC.
HTTP
--httpEnable the HTTP-RPC server--http.addrHTTP-RPC server listening interface (default:localhost)--http.portHTTP-RPC server listening port (default:8545)--http.apiAPI's offered over the HTTP-RPC interface (default:eth,net,web3)--http.corsdomainComma separated list of domains from which to accept cross origin requests (browser enforced)
WebSocket
--wsEnable the WS-RPC server--ws.addrWS-RPC server listening interface (default:localhost)--ws.portWS-RPC server listening port (default:8546)--ws.apiAPI's offered over the WS-RPC interface (default:eth,net,web3)--ws.originsOrigins from which to accept websockets requests
GraphQL
--graphqlEnable GraphQL on the HTTP-RPC server. Note that GraphQL can only be started if an HTTP server is started as well.--graphql.corsdomainComma separated list of domains from which to accept cross origin requests (browser enforced)--graphql.vhostsComma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard. (default: "localhost")
IPC
--ipcdisableDisable the IPC-RPC server--ipcapiAPI's offered over the IPC-RPC interface (default:admin,debug,eth,miner,net,personal,shh,txpool,web3)--ipcpathFilename for IPC socket/pipe within the datadir (explicit paths escape it)
Hex Value Encoding
Two key data types get passed over JSON: unformatted byte arrays and quantities. Both are passed with a hex encoding but with different requirements for formatting.
Quantities
When encoding quantities (integers, numbers): encode as hex, prefix with "0x", the most compact representation (slight exception: zero should be represented as "0x0").
Here are some examples:
0x41(65 in decimal)0x400(1024 in decimal)WRONG: 0x(should always have at least one digit - zero is "0x0")WRONG: 0x0400(no leading zeroes allowed)WRONG: ff(must be prefixed 0x)
Unformatted Data
When encoding unformatted data (byte arrays, account addresses, hashes, bytecode arrays): encode as hex, prefix with "0x", two hex digits per byte.
Here are some examples:
0x41(size 1, "A")0x004200(size 3, "0B0")0x(size 0, "")WRONG: 0xf0f0f(must be even number of digits)WRONG: 004200(must be prefixed 0x)
The Block Parameter
The block parameters are used when querying state at a particular block height or tag.
The following options are possible for the block parameter:
HEX String- an integer block numberString "earliest"for the earliest/genesis blockString "latest"- for the latest proposed blockString "safe"- for the latest safe head blockString "finalized"- for the latest finalized blockString "pending"- for the pending state/transactions
Usage & Execution
Examples of using the JSON-RPC API by making curl requests to a DAC Blockchain node are provided throughout each module.
To execute a request properly, you must include the -H "Content-Type: application/json" header and target your node's URL (e.g. 127.0.0.1:8545):
curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' 127.0.0.1:8545