Skip to content

RedDuck

SolidityProvider

Compile a Solidity contract, get a typed F# API for it — no codegen step, no hand-written DTOs.


SolidityProvider turns a contract's ABI into a typed F# API — deploy it, call its methods, decode its results and events — using an F# type provider that expands the members at compile time. No codegen step to rerun, no DTOs to hand-write; the moment the ABI changes, so does the type. Encoding, decoding and remote calls all go through Nethereum.

Built with

Area Technology
Language F# (netstandard2.0 + net8.0)
Type provider host FSharp.TypeProviders.SDK
Ethereum client Nethereum 6.x
ABI parsing System.Text.Json for artifact discovery, Newtonsoft.Json for Nethereum's ABI deserializer
Package management Paket
Tests xUnit
Compatible build tools Hardhat, or anything producing Hardhat/Truffle-shaped artifact json

How it works

flowchart LR
    A[Solidity contract] -->|hardhat compile| B[ABI + bytecode json]
    B --> C{SolidityProvider}
    C -->|design time| D[Generated FooContract type]
    D -->|ContractPlug| E[Nethereum]
    E --> F[Ethereum JSON-RPC node]
Loading
  1. Compile your contracts with anything that emits ABI/bytecode json - Hardhat's nested artifacts/ layout and a flat build folder both work.
  2. Point a type provider at the output, or let it compile for you.
  3. The compiler expands a real FooContract type: one member per function, event and constructor in the ABI.
  4. Instantiate it against an address, or deploy fresh by giving it constructor arguments.
type Contracts = AbiTypeProvider.AbiTypes<"./build/contracts">

let storageContract = Contracts.SimpleStorageContract(web3)
let getResult = storageContract.getQuery()
storageContract.set(newValue, weiValue 0UL, gasLlimit 8500000UL)

Swap in AbiTypeProvider.AbiTypesFromHardhat<"./hardhat.config.js"> and it runs npx hardhat compile for you before generating types. An example project is in example/.

Generated contract API

Member Behavior
fooQuery / fooQueryAsync Read-only call, decoded to a .NET value
foo / fooAsync State-changing call, returns a TransactionReceipt
fooData / fooTransactionInput Raw calldata / an unsent TransactionInput
FooEventDTO.DecodeAllEvents Decodes a receipt's logs into typed events

Getting started

Prerequisites: .NET 8 SDK (plus Node.js + npx for AbiTypesFromHardhat).

dotnet tool restore   # installs the Paket bootstrapper
dotnet paket install  # resolves NuGet dependencies
dotnet build -c Release
dotnet test tests/SolidityProviderTest/SolidityProviderTest.fsproj

License

GPL-3.0-or-later

About

Compile-time F# type provider for interacting with Ethereum smart contracts via Nethereum.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

9 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages