Skip to content

Commit

Permalink
add Eth API && Base API
Browse files Browse the repository at this point in the history
  • Loading branch information
zven21 committed Jun 28, 2022
1 parent 4b55e95 commit 51edb79
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
46 changes: 45 additions & 1 deletion guides/Base API.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
## :construction: Base API
## :construction: Base API

### Encoding and Decoding Helpers

1. Converts a hex string to a integer.

```elixir
iex> Web3.to_hex(10)
"0xA"

iex> Web3.to_hex("0xa")
"0xa"

iex> Web3.to_hex(true)
"0x1"
```

2. Converts a integer to hex.

```elixir
iex> Web3.to_hex(10)
"0xA"

iex> Web3.to_hex("0xa")
"0xa"

iex> Web3.to_hex(true)
"0x1"
```

### Address Helpers

- [ ] Web3.is_address/1
- [ ] Web3.is_checksum_address/1

### Currency Conversions

- [ ] Web3.to_wei/1
- [ ] Web3.from_wei/1

### Cryptographic Hashing

- [ ] Web3.keccak256/1

More details found [here](https://hexdocs.pm/web3/Web3.html)
44 changes: 43 additions & 1 deletion guides/ETH API.md
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
## :construction: ETH API
## ETH API

Web3 has the following methods built in:

- eth_blockNumber/0
- eth_getBalance/2
- eth_getBlockByHash/2
- eth_getBlockByNumber/2
- eth_getCode/2
- net_version/0
- eth_getTransactionByHash/1
- eth_getUncleByBlockHashAndIndex/2
- eth_getTransactionByBlockHashAndIndex/2
- eth_getTransactionByBlockNumberAndIndex/2
- eth_getBlockTransactionCountByHash/1
- eth_getBlockTransactionCountByNumber/1
- eth_getTransactionReceipt/1
- eth_gasPrice/0
- eth_getTransactionCount/2
- eth_sendRawTransaction/1

You can get details at [Infura.io](https://docs.infura.io/infura/networks/ethereum/json-rpc-methods/eth_gasprice)

By the way, you can define the eth API.

```elixir
defmodule MyApp.MyApplication do
use Web3, rpc_endpoint: "https://bsc-dataseed4.ninicoin.io"

dispatch :eth_chainId, args: 0
end
```

Macro dispatch receives 2 parameters.

- Infura same method name, e.g.: :eth_chainId
- Options:

Field | Required| Description | Default
----------- | --------| --------- | -------------
`name` | `false` | Alias name | (empty)
`args` | `false` | Number of parameters received by the method | 0
`return_fn` | `false` | Return value types, you can use anonymous functions | :raw

0 comments on commit 51edb79

Please sign in to comment.