bs-eth
v0.4.0
Published
Web3 like library for ReasonML/Bucklescript
Maintainers
Readme
Really Basic ReasonML web3 like interface
The goal is for this to support most common web3 functionality in ReasonML as well as some less common functionality that I need.
I am currently learning ReasonML and using this as an exercise at implementing something I understand fairly well (web3) using ReasonMl.
This means the API is likely going to change a lot as I learn more about idiomatic ReasonML and fix stupid beginners mistakes.
Setting up a Provider
There is currently support for the following providers that both live in the Providers namespace:
Providers.web3(web3provider)which wraps an existing web3 provider eg. MetaMaskProviders.http(url)which is configured with a url to a http based provider like infura
Once you have a provider you pass it as a parameter to all the functions in the Eth namespace.
let provider = Providers.http("https://mainnet.infura.io/bs-eth");
netVersion(provider)
|> Repromise.wait(result => switch (result) {
| Ok(netId) => Js.log("we are on the " ++ string_of_int(netId) ++ " chain")
| Error(msg) => Js.log(msg)
});Calling functions
All functions in the Eth module return typed Belt.Result in a Repromise. So instead of looking out for rejected calls, do a pattern match.
See the List of Methods implemented for more details.
Roadmap
- [x] Fetch based https provider interface
- [x] Wrap javascript Web3 provider (a la metamask)
- [x] Most common JSON-RPC methods implemented (In bold below)
- [x] Basic Documentation
- [ ] Solidity ABI codec in native reasonml
- [ ] Add support for WebSocket provider
- [ ] Filter support with support for some sort of reactive streams. Maybe wonka
- [ ] Implement complete wrappers for the JSON-RPC apps methods listed below
- [ ] EIP 712 support
- [ ] Add RLP encoder to be able to encode transactions for signing
- [ ] Allow signing in ReasonML using WASM
- [ ] Support for bs-native
Ethereum JSON-RPC Implemented Methods
The RPC methods currently implemented are:
- [x]
eth_accountsasaccounts() - [x]
eth_blockNumberasblockNumber() - [x]
eth_callascall() - [x]
eth_coinbaseascoinbase() - [x]
eth_estimateGasasestimateGas() - [x]
eth_gasPriceasgasPrice() - [x]
eth_getBalanceasbalanceOf() - [x]
eth_getBlockByNumberasblockByNumber - [x]
eth_getBlockByHashasblockByHash - [ ]
eth_getBlockTransactionCountByHash - [ ]
eth_getBlockTransactionCountByNumber - [ ]
eth_getCode - [ ]
eth_getCompilers - [ ]
eth_getFilterChanges - [ ]
eth_getFilterLogs - [ ]
eth_getLogs - [ ]
eth_getStorageAt - [x]
eth_getTransactionByHashastransactionByHash() - [ ]
eth_getTransactionByBlockHashAndIndex - [ ]
eth_getTransactionByBlockNumberAndIndex - [x]
eth_getTransactionCountastransactionCount() - [x]
eth_getTransactionReceiptas `transactionReceipt() - [ ]
eth_hashrate - [ ]
eth_mining - [ ]
eth_newBlockFilter - [ ]
eth_newFilter(includes log/event filters) - [ ]
eth_protocolVersion - [x]
eth_sendTransactionassendTransaction() - [x]
eth_sendRawTransactionassendRawTransaction() - [ ]
eth_subscribe(only for websocket connections. "syncing" subscriptions are not yet supported) - [ ]
eth_unsubscribe(only for websocket connections. "syncing" subscriptions are not yet supported) - [ ]
eth_syncing - [ ]
eth_uninstallFilter - [ ]
net_listening - [ ]
net_peerCount - [x]
net_versionasnetVersion()
Non-Standard ganache-cli methods:
- [ ]
evm_snapshot - [ ]
evm_revert - [ ]
evm_increaseTime - [x]
evm_mineasmineBlock()
