github.com/amazechain/amc@v0.1.3/docs/jsonrpc/intro.md (about)

     1  # JSON-RPC
     2  
     3  You can interact with amc over JSON-RPC. amc supports all standard Ethereum JSON-RPC API methods.
     4  
     5  JSON-RPC is provided on multiple transports. amc supports HTTP, WebSocket and IPC (both UNIX sockets and Windows named pipes). Transports must be enabled through command-line flags.
     6  
     7  The JSON-RPC APIs are grouped into namespaces, depending on their purpose. All method names are composed of their namespace and their name, separated by an underscore.
     8  
     9  Each namespace must be explicitly enabled.
    10  
    11  ## Namespaces
    12  
    13  The methods are grouped into namespaces, which are listed below:
    14  
    15  | Namespace               | Description                                                                                            | Sensitive |
    16  |-------------------------|--------------------------------------------------------------------------------------------------------|-----------|
    17  | [`eth`](./eth.md)       | The `eth` API allows you to interact with Ethereum.                                                    | Maybe     |
    18  | [`web3`](./web3.md)     | The `web3` API provides utility functions for the web3 client.                                         | No        |
    19  | [`net`](./net.md)       | The `net` API provides access to network information of the node.                                      | No        |
    20  | [`txpool`](./txpool.md) | The `txpool` API allows you to inspect the transaction pool.                                           | No        |
    21  | [`debug`](./debug.md)   | The `debug` API provides several methods to inspect the Ethereum state, including Geth-style traces.   | No        |
    22  | [`trace`](./trace.md)   | The `trace` API provides several methods to inspect the Ethereum state, including Parity-style traces. | No        |
    23  | [`admin`](./admin.md)   | The `admin` API allows you to configure your node.                                                     | **Yes**   |
    24  | [`rpc`](./rpc.md)       | The `rpc` API provides information about the RPC server and its modules.                               | No        |
    25  
    26  Note that some APIs are sensitive, since they can be used to configure your node (admin), or access accounts stored on the node (eth).
    27  
    28  Generally, it is advisable to not expose any JSONRPC namespace publicly, unless you know what you are doing.
    29  
    30  
    31  ## Transports
    32  
    33  amc supports HTTP, WebSockets and IPC.
    34  
    35  ### HTTP
    36  
    37  Using the HTTP transport, clients send a request to the server and immediately get a response back. The connection is closed after the response for a given request is sent.
    38  
    39  Because HTTP is unidirectional, subscriptions are not supported.
    40  
    41  To start an HTTP server, pass --http to amc node:
    42  
    43  ```bash
    44  amc --http
    45  ```
    46  
    47  The default port is 8545, and the default listen address is localhost.
    48  
    49  You can configure the listen address and port using --http.addr and --http.port respectively:
    50  
    51  ```bash
    52  amc --http --http.addr 127.0.0.1 --http.port 12345
    53  ```
    54  
    55  To enable JSON-RPC namespaces on the HTTP server, pass each namespace separated by a comma to --http.api:
    56  
    57  ```bash
    58  amc --http --http.api eth,net,trace
    59  ```
    60  
    61  You can pass the `all` option, which is a convenient wrapper for the all the JSON-RPC namespaces `admin,debug,eth,net,trace,txpool,web3,rpc` on the HTTP server:
    62  
    63  ```bash
    64  amc --http --http.api all
    65  ```
    66  
    67  ```bash
    68  amc --http --http.api All
    69  ```
    70  
    71  You can also restrict who can access the HTTP server by specifying a domain for Cross-Origin requests. This is important, since any application local to your node will be able to access the RPC server:
    72  
    73  ```bash
    74  amc --http --http.corsdomain https://mycoolapp.rs
    75  ```
    76  
    77  Alternatively, if you want to allow any domain, you can pass `*`:
    78  
    79  ```bash
    80  amc --http --http.corsdomain "*"
    81  ```
    82  
    83  ### WebSockets
    84  
    85  WebSockets is a bidirectional transport protocol. Most modern browsers support WebSockets.
    86  
    87  A WebSocket connection is maintained until it is explicitly terminated by either the client or the node.
    88  
    89  Because WebSockets are bidirectional, nodes can push events to clients, which enables clients to subscribe to specific events, such as new transactions in the transaction pool, and new logs for smart contracts.
    90  
    91  The configuration of the WebSocket server follows the same pattern as the HTTP server:
    92  
    93  - Enable it using `--ws`
    94  - Configure the server address by passing `--ws.addr` and `--ws.port` (default `8546`)
    95  - Configure cross-origin requests using `--ws.origins`
    96  - Enable APIs using `--ws.api`
    97  
    98  ### IPC
    99  
   100  IPC is a simpler transport protocol for use in local environments where the node and the client exist on the same machine.
   101  
   102  The IPC transport is enabled by default and has access to all namespaces, unless explicitly disabled with `--ipcdisable`.
   103  
   104  Reth creates a UNIX socket on Linux and macOS at `/tmp/amc.ipc`. On Windows, IPC is provided using named pipes at `\\.\pipe\amc.ipc`.
   105  
   106  You can configure the IPC path using `--ipcpath`.
   107  
   108  ## Interacting with the RPC
   109  
   110  One can easily interact with these APIs just like they would with any Ethereum client.
   111  
   112  You can use `curl`, a programming language with a low-level library, or a tool like Foundry to interact with the chain at the exposed HTTP or WS port.
   113  
   114  As a reminder, you need to run the command below to enable all of these APIs using an HTTP transport:
   115  
   116  ```bash
   117  RUST_LOG=info reth node --http --http.api "admin,debug,eth,net,trace,txpool,web3,rpc"
   118  ```
   119  
   120  This allows you to then call:
   121  
   122  ```bash
   123  cast block-number
   124  cast rpc admin_nodeInfo
   125  cast rpc debug_traceTransaction
   126  cast rpc trace_replayBlockTransactions
   127  ```