No description
Find a file
2025-12-22 11:02:24 +01:00
.github/workflows rm unused Windows i386 CI support (#227) 2025-10-10 13:27:15 +00:00
tests Make totalDifficulty optional in BlockObject (#233) 2025-12-22 11:02:24 +01:00
web3 Make totalDifficulty optional in BlockObject (#233) 2025-12-22 11:02:24 +01:00
.editorconfig Add encodeTransaction for other TxType (#179) 2024-11-26 11:48:01 +07:00
.gitignore feat: abi encoder / decoder (#216) 2025-08-28 14:51:34 +02:00
.gitmodules Feature/execution api spec (#69) 2024-01-11 21:02:42 +07:00
ci-test.sh feat: abi encoder / decoder (#216) 2025-08-28 14:51:34 +02:00
config.nims v0.2.0: Revamp data types 2023-12-12 12:15:34 +07:00
LICENSE-APACHEv2 Initial commit 2018-12-21 18:27:09 +01:00
LICENSE-MIT Initial commit 2018-12-21 18:27:09 +01:00
nim.cfg re-enable ObservableStores and GcUnsafe2 warnings (#177) 2024-10-25 02:06:48 +00:00
README.md feat: abi encoder / decoder (#216) 2025-08-28 14:51:34 +02:00
simulator.sh Replace ganache-cli with hardhat (#154) 2024-09-29 22:48:19 +02:00
web3.nim feat: abi encoder / decoder (#216) 2025-08-28 14:51:34 +02:00
web3.nimble v0.8.0 (#226) 2025-09-25 17:42:36 +00: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.