mirror of
https://github.com/status-im/nim-web3.git
synced 2026-08-27 10:31:06 +00:00
master
* newWeb3: Do not silence exceptions, let the function raise.
* Fix raises syntax.
* Add esplicit `(raises: [CatchableError])` to `async`.
Even though this is equivalent to `{.async.}`, the intention is more
clear this way.
* Remove discard from future.
Discarding futures is discouraged:
https://status-im.github.io/nim-chronos/tips.html#discard
* Replace await with asyncSpawn.
It was discard earlier, asyncSpawn is Chronos's replacement for discard.
* Add web3-specific exceptions.
* Raise specific exceptions.
* Require json_rpc#head.
Temporary, until the new release is cut.
* CI: Add Nim 2.4 to matrix.
* Update json_rpc requirement.
* Update web3.nim
Co-authored-by: Jacek Sieka <jacek@status.im>
* Avoid iterating over changing value.
* Ensure that only Web3Error exceptions are raised from web3.
Note: SerializationError from json_serialization is caught and re-raised
as web3.SerializationError.
* Rename SerializationError to AbiSerializationError.
* Declare only Web3Error as raised.
Instead of specific Web3Error subclass exceptions.
---------
Co-authored-by: Jacek Sieka <jacek@status.im>
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.
Languages
Nim
99.7%
Shell
0.3%