Constantine MolchanovandJacek Sieka 68b493cc43 Upgrade error handling to checked raises (#259)
* 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>
2026-08-26 14:26:10 +00:00
2026-07-06 20:39:33 +07:00
2024-01-11 21:02:42 +07:00
2018-12-21 18:27:09 +01:00
2018-12-21 18:27:09 +01:00
2025-08-28 14:51:34 +02:00

web3

License: MIT License: Apache Stability: experimental Github action

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

or

at your option. This file may not be copied, modified, or distributed except according to those terms.

S
Description
No description provided
Readme
2 MiB
Languages
Nim 99.7%
Shell 0.3%