Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5ec4dac
prepare for getBlobsV2
agnxsh Apr 1, 2025
faf3ac6
Revert "prepare for getBlobsV2"
agnxsh Apr 1, 2025
3fffb22
accomodate getBlobsV2
agnxsh Apr 6, 2025
97784b5
Revert "accomodate getBlobsV2"
agnxsh Apr 6, 2025
57a1daa
getBlobsV2 (#199)
agnxsh Apr 6, 2025
e577619
use spec names for spec constants (#200)
tersec Apr 7, 2025
3ef986c
Fusaka: Add EIP-7873 fields to TransactionObject/TransactionArgs (#198)
jangko Apr 15, 2025
1c15d1f
Bump nim-eth minimum to 0.7.0 (#203)
etan-status Apr 22, 2025
d35250b
v0.6.0 (#204)
etan-status Apr 22, 2025
8460999
init payloadV5 (#201)
agnxsh Apr 23, 2025
7de20af
rm EIP-7873 support (#206)
tersec May 16, 2025
d088731
Bump nim-eth minimum to 0.8.0 (#207)
etan-status May 21, 2025
85af8f2
v0.7.0 (#208)
etan-status May 21, 2025
6231ca3
Replace PooledTransaction usage from test with BlobTx (#210)
jangko Jun 27, 2025
440c628
chore: improve readme (#212)
2-towns Jul 22, 2025
6d46159
json: adapt to array streaming API changes (#211)
arnetheduck Jul 22, 2025
304afd1
On JSON-RPC, authorization serializes v as yParity (#209)
etan-status Jul 30, 2025
81ee8ce
eth_config endpoint addition (#217)
advaita-saha Aug 6, 2025
48fb2d4
feat: abi encoder / decoder (#216)
2-towns Aug 28, 2025
d62470d
remove macos-13 from the matrix (#221)
narimiran Sep 1, 2025
c2b10b4
fix (#223)
chirag-parmar Sep 4, 2025
141907c
fix: readValue UInt256 error (#224)
fryorcraken Sep 15, 2025
cdfe560
v0.8.0 (#226)
arnetheduck Sep 25, 2025
5ac7da0
rm unused Windows i386 CI support (#227)
tersec Oct 10, 2025
7d85d5b
add focil related engine changes
RazorClient Oct 17, 2025
645186c
add Inclusionlist params
RazorClient Oct 18, 2025
065e472
fixes
RazorClient Oct 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
cpu: amd64
- os: linux
cpu: i386
- os: macos
cpu: amd64
- os: macos
cpu: arm64
- os: windows
Expand All @@ -35,11 +33,6 @@ jobs:
os: linux-gcc-14 # This is to use ubuntu 24 and install gcc 14. Should be removed when ubuntu-latest is 26.04
builder: ubuntu-24.04
shell: bash
- target:
os: macos
cpu: amd64
builder: macos-13
shell: bash
- target:
os: macos
cpu: arm64
Expand Down Expand Up @@ -82,17 +75,6 @@ jobs:
chmod 755 external/bin/gcc external/bin/g++
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH

- name: MSYS2 (Windows i386)
if: runner.os == 'Windows' && matrix.target.cpu == 'i386'
uses: msys2/setup-msys2@v2
with:
path-type: inherit
msystem: MINGW32
install: >-
base-devel
git
mingw-w64-i686-toolchain

- name: MSYS2 (Windows amd64)
if: runner.os == 'Windows' && matrix.target.cpu == 'amd64'
uses: msys2/setup-msys2@v2
Expand Down Expand Up @@ -155,13 +137,24 @@ jobs:
echo "ncpu=$ncpu" >> $GITHUB_ENV
echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV

- name: Configure ARM64 build environment (macOS)
if: runner.os == 'macOS' && matrix.target.cpu == 'arm64'
run: |
# Force ARM64 architecture for Nim compilation with proper flags passed to clang
echo "NIMFLAGS=--cpu:arm64 --cc:clang --passC:\"-target arm64-apple-macos11\" --passL:\"-target arm64-apple-macos11\"" >> $GITHUB_ENV

- name: Build Nim and Nimble
run: |
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh
env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ matrix.branch }} \
QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \
bash build_nim.sh nim csources dist/nimble NimBinaries
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
- name: Setup Nimble
uses: nim-lang/setup-nimble-action@v1
with:
nimble-version: 'latest'
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Use gcc 14
# Should be removed when ubuntu-latest is 26.04
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build/
*.exe
*.dll
nimble.paths
nimbledeps

node_modules
nohup.out
Expand Down
70 changes: 68 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,82 @@ The humble beginnings of a Nim library similar to web3.[js|py]

## Installation

You can install the developement version of the library through nimble with the following command
You can install the development version of the library through nimble with the following command

```console
nimble install https://github.com/status-im/nim-web3@#master
```

## Development

You should first run `./simulator.sh` which runs `hardhat node`
First, fetch the submodules:

```bash
git submodule update --init --recursive
```

Install nodemon globally, hardhat locally and create a `hardhat.config.js` file:

```bash
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][1] using nim-serialization interface.

Usage
-----

```nim
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
Expand All @@ -32,3 +96,5 @@ or
- Apache License, Version 2.0, ([LICENSE-APACHEv2](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.

[1]: https://docs.soliditylang.org/en/latest/abi-spec.html
8 changes: 5 additions & 3 deletions ci-test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/sh
#!/bin/bash

set -ex
npm install hardhat
touch hardhat.config.js
npm install hardhat@3
npm pkg set type="module"
echo "export default {};" > hardhat.config.js
npx hardhat --version
nohup npx hardhat node &
nimble install -y --depsOnly

Expand Down
6 changes: 5 additions & 1 deletion tests/all_tests.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ import
test_signed_tx,
test_execution_types,
test_string_decoder,
test_abi_utils,
test_encoding,
test_decoding,
test_abi_serialization,
test_contract_dsl,
test_execution_api
test_execution_api
7 changes: 4 additions & 3 deletions tests/helpers/handlers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import
json_rpc/rpcserver,
../../web3/conversions,
../../web3/eth_api_types,
../../web3/primitives as w3
../../web3/primitives as w3,
./min_blobtx_rlp

type
Hash32 = w3.Hash32
Expand All @@ -29,8 +30,8 @@ proc installHandlers*(server: RpcServer) =
return SyncingStatus(syncing: false)

server.rpc("eth_sendRawTransaction") do(x: JsonString, data: seq[byte]) -> Hash32:
let tx = rlp.decode(data, PooledTransaction)
let h = rlpHash(tx)
let tx = rlp.decode(data, BlobTransaction)
let h = computeRlpHash(tx.tx)
return Hash32(h.data)

server.rpc("eth_getTransactionReceipt") do(x: JsonString, data: Hash32) -> ReceiptObject:
Expand Down
29 changes: 29 additions & 0 deletions tests/helpers/min_blobtx_rlp.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{.push raises: [].}

import
eth/common/transactions_rlp {.all.}

type
# Pretend to be a PooledTransaction
# for testing purpose
BlobTransaction* = object
tx*: Transaction

proc readTxTyped(rlp: var Rlp, tx: var BlobTransaction) {.raises: [RlpError].} =
let
txType = rlp.readTxType()
numFields =
if txType == TxEip4844:
rlp.listLen
else:
1
if numFields == 4 or numFields == 5:
rlp.tryEnterList() # spec: rlp([tx_payload, blobs, commitments, proofs])
rlp.readTxPayload(tx.tx, txType)
# ignore BlobBundle

proc read*(rlp: var Rlp, T: type BlobTransaction): T {.raises: [RlpError].} =
if rlp.isList:
rlp.readTxLegacy(result.tx)
else:
rlp.readTxTyped(result)
67 changes: 67 additions & 0 deletions tests/test_abi_serialization.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import
std/unittest,
serialization,
std/random,
../web3/encoding,
../web3/decoding,
../web3/eth_api_types,
../web3/abi_serialization

type Contract = object
a: uint64
b {.dontSerialize.}: string
c: bool
d: string

type StorageDeal = object
client: array[20, byte]
provider: array[20, byte]
cid: array[32, byte]
size: uint64
duration: uint64
pricePerByte: UInt256
signature: array[65, byte]
metadata: string

proc randomBytes[N: static int](): array[N, byte] =
var a: array[N, byte]
for b in a.mitems:
b = rand(byte)
return a

suite "ABI serialization":
test "encode and decode custom type":
let x = Contract(a: 1, b: "SECRET", c: true, d: "hello")

let encoded = Abi.encode(x)
check encoded == Abi.encode((x.a, x.c, x.d))

let decoded = Abi.decode(encoded, Contract)
check decoded.a == x.a
check decoded.b == ""
check decoded.c == x.c
check decoded.d == x.d

test "encode and decode complex type":
let deal = StorageDeal(
client: randomBytes[20](),
provider: randomBytes[20](),
cid: randomBytes[32](),
size: 1024'u64,
duration: 365'u64,
pricePerByte: 1000.u256,
signature: randomBytes[65](),
metadata: "Sample metadata for storage deal"
)

let encoded = Abi.encode(deal)
let decoded = Abi.decode(encoded, StorageDeal)

check decoded.client == deal.client
check decoded.provider == deal.provider
check decoded.cid == deal.cid
check decoded.size == deal.size
check decoded.duration == deal.duration
check decoded.pricePerByte == deal.pricePerByte
check decoded.signature == deal.signature
check decoded.metadata == deal.metadata
15 changes: 15 additions & 0 deletions tests/test_abi_utils.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import
std/unittest,
../web3/abi_utils

suite "ABI utils":
test "can determine whether types are dynamic or static":
check static isStatic(uint8)
check static isDynamic(seq[byte])
check static isStatic(array[2, array[2, byte]])
check static isDynamic(array[2, seq[byte]])
check static isStatic((uint8, bool))
check static isDynamic((uint8, seq[byte]))
check static isStatic((uint8, (bool, uint8)))
check static isDynamic((uint8, (bool, seq[byte])))
1 change: 1 addition & 0 deletions tests/test_contract_dsl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import
pkg/unittest2,
stew/byteutils,
stint,
../web3/encoding,
../web3/contract_dsl

type
Expand Down
Loading