mirror of
https://github.com/status-im/nim-web3
synced 2026-01-02 10:04:43 +00:00
No description
| .github/workflows | ||
| tests | ||
| web3 | ||
| .editorconfig | ||
| .gitignore | ||
| .gitmodules | ||
| ci-test.sh | ||
| config.nims | ||
| LICENSE-APACHEv2 | ||
| LICENSE-MIT | ||
| nim.cfg | ||
| README.md | ||
| simulator.sh | ||
| web3.nim | ||
| web3.nimble | ||
web3
The humble beginnings of a Nim library similar to web3.[js|py]
Installation
You can install the development version of the library through nimble with the following command
nimble install https://github.com/status-im/nim-web3@#master
Development
First, fetch the submodules:
git submodule update --init --recursive
Install nodemon globally, hardhat locally and create a hardhat.config.js file:
npm install -g nodemon
npm install hardhat
echo "module.exports = {};" > hardhat.config.js
Then you should run ./simulator.sh which runs hardhat node
This creates a local simulated Ethereum network on your local machine and the tests will use this for their E2E processing
ABI encoder / decoder
Implements encoding of parameters according to the Ethereum Contract ABI Specification using nim-serialization interface.
Usage
import
serialization,
stint,
web3/[encoding, decoding]
# encode unsigned integers, booleans, enums
Abi.encode(42'u8)
# encode uint256
Abi.encode(42.u256)
# encode byte arrays and sequences
Abi.encode([1'u8, 2'u8, 3'u8])
Abi.encode(@[1'u8, 2'u8, 3'u8])
# encode tuples
Abi.encode( (42'u8, @[1'u8, 2'u8, 3'u8], true) )
# decode values of different types
Abi.decode(bytes, uint8)
Abi.decode(bytes, UInt256)
Abi.decode(bytes, array[3, uint8])
Abi.decode(bytes, seq[uint8])
# decode tuples
Abi.decode(bytes, (uint32, bool, seq[byte]))
# custom type
type Contract = object
a: uint64
b {.dontSerialize.}: string
c: bool
let encoded = Abi.encode(x)
let decoded = Abi.decode(encoded, Contract)
# encoded.a == decoded.a
# encoded.b == ""
# encoded.c == decoded.c
License
Licensed and distributed under either of
- MIT license: LICENSE-MIT or http://opensource.org/licenses/MIT
or
- Apache License, Version 2.0, (LICENSE-APACHEv2 or http://www.apache.org/licenses/LICENSE-2.0)
at your option. This file may not be copied, modified, or distributed except according to those terms.