Berachain RPC (Remote Procedure Call) is a powerful tool that allows developers to interact with the Berachain blockchain directly. It provides an interface to send and receive data from the blockchain, enabling the creation of custom applications and services. This comprehensive guide will introduce you to the basics of Berachain RPC and provide detailed instructions on using 101 essential commands.
To establish a RPC connection, you will need to use a command-line tool such as cURL or Postman. The following command establishes a connection using cURL:
curl -u [rpcuser]:[rpcpassword] -X POST http://[rpcserver]:[rpcport]/ -d '{"jsonrpc":"1.0","id":"curltest","method":"getblockcount","params":[]}'
Replace '[rpcuser]' with your RPC username, '[rpcpassword]' with your RPC password, '[rpcserver]' with your RPC server address, and '[rpcport]' with your RPC port (usually 18245).
Description: Provides information about the current state of the blockchain, including block height, difficulty, and network hashrate.
Usage:
{"jsonrpc":"1.0","id":"1","method":"getblockchaininfo","params":[]}
Response Sample:
{
"chain": "main",
"blocks": 554803,
"headers": 554803,
"bestblockhash": "00000000000000000009156f17704629446231f521774f2f9e9169e534f33433",
"difficulty": 8672870782986,
"mediantime": 1624778717,
"verificationprogress": 0.999996703781324,
"initialblockdownload": false,
"chainwork": "00000000000000000000000000000000000000000000000000001ef32d621383",
"size_on_disk": 18883283,
"pruned": false,
"softforks": [
{
"id": "bip34",
"version": 2,
"enforce": {
"status": true,
"found": 1000000,
"required": 1000000
}
},
{
"id": "bip66",
"version": 3,
"enforce": {
"status": true,
"found": 1000000,
"required": 1000000
}
},
{
"id": "bip65",
"version": 4,
"enforce": {
"status": true,
"found": 1000000,
"required": 1000000
}
},
],
"bip9_softforks": {
"csv": {
"status": "active",
"startTime": 1493172604,
"timeout": 46800,
"since": 472127
},
"segwit": {
"status": "active",
"startTime": 1493427169,
"timeout": 46800,
"since": 504938
},
"discouragement": {
"status": "active",
"startTime": 1513421654,
"timeout": 91200,
"since": 618470
}
}
}
Description: Returns the current block height.
Usage:
{"jsonrpc":"1.0","id":"1","method":"getblockcount","params":[]}
Response Sample:
554803
Description: Gets the specified block by hash or height.
Usage:
{"jsonrpc":"1.0","id":"1","method":"getblock","params":["00000000000000000009156f17704629446231f521774f2f9e9169e534f33433"]}
Response Sample:
{
"hash": "00000000000000000009156f17704629446231f521774f2f9e9169e534f33433",
"confirmations": 2,
"size": 765,
"height": 554803,
"version": 536870912,
"merkleroot": "215be81526a967ac91d33ab32c3557ba29494504d5e8872961e5cfc79045f940",
"tx": [
"5f313577f6107f841544227e5195b26109ca1683cb94780747b64452b65dba3b",
"6d5a958097924a366f74a9e31db3d150d9c6625b5c63bfd1ac9080d9986089db",
"8fb17589d40dea15222a5ddea5371bb6b3981abbc6153d12db324056667e2558"
],
"time": 1624778717,
"nonce": 1953974143,
"bits": "1c451a3b",
"difficulty": 8672870782986,
"chainwork": "00000000000000000000000000000000000000000000000000001eaab6262be3",
"previousblockhash": "00000000000000000009156f27a91d8959078d857dd4406d04bad48e6541d80f",
"nextblockhash": "0000000000000000000298212b05892b51b3cfc21ccaf4e665801734b18f5706"
}
Description: Gets the raw transaction data for the specified transaction ID.
Usage:
{"jsonrpc":"1.0","id":"1","method":"getrawtransaction","params":["5f313577f6107f841544227e5195b26109ca1683cb94780747b64452b65dba3b"]}
Response Sample:
```
02000000017036cc33074cb7809467556701968f051c399662c6bbe5d6
2024-11-17 01:53:44 UTC
2024-11-18 01:53:44 UTC
2024-11-19 01:53:51 UTC
2024-08-01 02:38:21 UTC
2024-07-18 07:41:36 UTC
2024-12-23 02:02:18 UTC
2024-11-16 01:53:42 UTC
2024-12-22 02:02:12 UTC
2024-12-20 02:02:07 UTC
2024-11-20 01:53:51 UTC
2024-08-20 21:45:32 UTC
2024-08-09 19:40:16 UTC
2024-08-09 19:40:33 UTC
2024-08-09 19:40:40 UTC
2024-09-11 13:48:37 UTC
2024-08-09 12:29:33 UTC
2024-08-09 12:29:43 UTC
2024-08-09 12:29:52 UTC
2025-01-04 06:15:36 UTC
2025-01-04 06:15:36 UTC
2025-01-04 06:15:36 UTC
2025-01-04 06:15:32 UTC
2025-01-04 06:15:32 UTC
2025-01-04 06:15:31 UTC
2025-01-04 06:15:28 UTC
2025-01-04 06:15:28 UTC