Trouble with ethers.js interop

I’ve been an avid Ethereum/Web3 developer for the last three years and have recently taken an interest to functional programming, specifically rescript.

The ethers.js library is a staple in web3 development that allows interacting with EVM compatible blockchains. I’ve spent the last few days attempting to write basic bindings from Typescript to ReScript. It has been a struggle.

Everything I’ve read says bindings should be easy, small, compact, etc, but this is not what I’ve experienced trying to interop with ethers.

For example, I tried to write a partial binding to interact with ethers contract.queryFilter() method. It requires an Event as the return type. This type is large, full of type unions, etc. Is this just a matter of writing large modules and will be easier with experience?

What was your general strategy writing the bindings? Did you try to write bindings for the whole lib in one sitting, or did you write bindings while you were building an app using that library?

Writing on demand bindings for your specific app needs is generally easier (but I know most ppl love to write universal bindings when they start out)

That said, some libraries (especially those relying heavily on classes, inheritance, tagged unions) tend to be very hard to bind to.

1 Like

Just tried to bind the functions I needed, as it is a small subset of an otherwise massive library.

I’m feeling that its just heavy on the paradigms you listed. I keep running into odd types, so it must just be my lack of comfort in rescript.

This typing has been giving me trouble
[ key: string ]: any;

This would be equivalent to a Js.Dict.t<something>, but I don’t know what your something is supposed to be, so probably instead of any you can use an abstract type and make it more concrete later?

module SomeItem = {
  type t
}

type someItemDict = Js.Dict.t<SomeItem.t>

1 Like

Thanks I was close to that. Appreciate the help :slight_smile:

BTW Would be interested to use this as some point - feel free to open source and others may contribute :).

1 Like