Custom implementation of Web3 in C++.
This is NOT a 100% parity conversion of the web3js library, but rather a mix of web3js structure with some logic from the now deprecated aleth library from Ethereum.
See Differences from web3js for more details on how this project deviates from web3js.
- CMake 3.19.0 or higher
- GCC with support for C++17 or higher
- Boost, libhidapi and OpenSSL
- (optional) Doxygen for generating the docs
- Clone the project:
git clone https://github.com/avme/web3cpp
- Go to the project's root folder, create a "build" folder and change to it:
cd web3cpp && mkdir build && cd build
- Run
cmake ..
thencmake --build . -- -j$(nproc)
inside the build folder - If you want documentation, go back to the project's root folder and run
doxygen Doxyfile
from there- Docs will be generated at a folder named
docs/html
- Docs will be generated at a folder named
For use with cmake -D<param> ..
:
BUILD_STATIC
(default ON) - compiles the library as staticBUILD_TESTS
(default ON) - compiles an extra program that runs some tests on the library
Due to architectural differences between JS and C++, most things were significantly changed. It's recommended to generate and read the docs from this project (see Instructions instead of following other implementations.
web3.utils
becomesnamespace Utils
- e.g. web3.utils.sha3("Hello!%") -> Utils::sha3("Hello!%")
web3.eth.Contract
becomesclass Contract
- e.g. var c = new web3.eth.Contract(...) -> Contract c(...)
web3.eth.abi
becomesnamespace Solidity
- e.g. web3.eth.abi.encodeParameters(['uint256','string'], ['2345675643', 'Hello!%']) -> Solidity::packMulti({{{"t", "uint256"}, {"v", "2345675643"}}, {{"t", "string"}, {"v", "Hello!%"}}}, err)
- The "network" part of
web3.*.net
is technically replaced bynamespace Net
(which does HTTP requests) andnamespace RPC
(which builds the data that is sent through the requests)- They're meant to be used together (e.g. Net::HTTPRequest(provider, Net::RequestTypes::POST, RPC::eth_getBlockNumber().dump()))
- The "node" part of
web3.*.net
is replaced byclass Provider
- Parts of
web3.eth.accounts
andweb3.eth.personal
are joined in a customWallet
class web3.eth
becomesclass Eth
and almost all of its member variables were moved toProvider
and/orContract::Options
- You still access
Provider
,Wallet
andEth
from inside the Web3 class- e.g. web3->getProvider()->getChainId(), web3->wallet.getAccounts(), web3->eth.getGasPrice()
- JavaScript's
BN.js
object is replaced by a simple unsigned 256-bit integer (aleth'sdev::u256
), which is aliased toBigNumber
- JSON objects are handled using nlohmann::json
Some particular things are not (and probably won't be) implemented as we either don't have a need for them (at least for now) or other parts of the library are already doing their job.
- web3.bzz (Swarm Protocol)
- web3.shh (Whisper Protocol)
- web3.eth.ens (Ethereum Name Service)
- web3.eth.Iban (IBAN/BBAN support)
- web3.eth.subscribe
- This one will probably be implemented inside
Contract
but it's not set in stone
- This one will probably be implemented inside
- Bloom filters on web3.utils
- BatchRequest
- PromiEvent
- Access lists
- Extending modules
- Other individual functions across some modules ("if it's not in the docs, we're not missing it")