Skip to content

Commit

Permalink
Documentation pass
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanasa committed Sep 13, 2023
1 parent 263657e commit 8fb96ff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 20 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ Make a request to a Web2 Ethereum node using a registered provider for a JSON RP
* `max_response_bytes`: See `request`.
* `EthRpcResult`: See `request`.

### `request_cost`

Calculate the cost of sending a request with the given input arguments.

request_cost: (service_url: text, json_rpc_payload: text, max_response_bytes: nat64) -> (nat) query;

* `service_url`: The URL of the service, including any API key if required for access-protected services.
* `json_rpc_payload`: See `request`.
* `max_response_bytes`: See `request`.

### `provider_request_cost`

Calculate the cost of sending a request with the given input arguments.

provider_request_cost: (provider_id: nat64, json_rpc_payload: text, max_response_bytes: nat64) -> (nat) query;

* `provider_id`: The id of the registered provider to be used for this call. This uniquely identifies a provider registered with the canister.
* `json_rpc_payload`: See `request_cost`.
* `max_response_bytes`: See `request_cost`.

### `unregister_provider`

Unregister a provider from the canister. Only the owner of the provider or an admin principal is authorized to perform this action.
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,18 @@ dfx canister call ic_eth get_authorized '(variant { Rpc })'
dfx canister call ic_eth deauthorize "(principal \"$PRINCIPAL\", variant { Rpc })"
```

### Local Ethereum RPC calls
### Ethereum RPC (local replica)
```bash
# Use a custom provider
dfx canister call --wallet $(dfx identity get-wallet) --with-cycles 600000000 ic_eth request '("https://cloudflare-eth.com","{\"jsonrpc\":\"2.0\",\"method\":\"eth_gasPrice\",\"params\":[],\"id\":1}",1000)'
dfx canister call --wallet $(dfx identity get-wallet) --with-cycles 600000000 ic_eth request '("https://ethereum.publicnode.com","{\"jsonrpc\":\"2.0\",\"method\":\"eth_gasPrice\",\"params\":[],\"id\":1}",1000)'

# Register your own provider
dfx canister call ic_eth register_provider '(record { chain_id=1; service_url="https://cloudflare-eth.com"; api_key="/v1/mainnet"; cycles_per_call=10; cycles_per_message_byte=1; })'
dfx canister call --wallet $(dfx identity get-wallet) --with-cycles 600000000 ic_eth provider_request '(0,"{\"jsonrpc\":\"2.0\",\"method\":\"eth_gasPrice\",\"params\":[],\"id\":1}",1000)'
```

### Mainnet Ethereum RPC calls
### Ethereum RPC (IC mainnet)
```bash
dfx canister --network ic call --wallet $(dfx identity --network ic get-wallet) --with-cycles 600000000 ic_eth request '("https://cloudflare-eth.com","{\"jsonrpc\":\"2.0\",\"method\":\"eth_gasPrice\",\"params\":[],\"id\":1}",1000)'
dfx canister --network ic call --wallet $(dfx identity --network ic get-wallet) --with-cycles 600000000 ic_eth request '("https://ethereum.publicnode.com","{\"jsonrpc\":\"2.0\",\"method\":\"eth_gasPrice\",\"params\":[],\"id\":1}",1000)'
Expand Down

0 comments on commit 8fb96ff

Please sign in to comment.