Skip to content

Instantly share code, notes, and snippets.

@thelissimus
Created April 8, 2024 18:27
Show Gist options
  • Save thelissimus/36d6bf8b180ccc8aff24f35f9e003fc5 to your computer and use it in GitHub Desktop.
Save thelissimus/36d6bf8b180ccc8aff24f35f9e003fc5 to your computer and use it in GitHub Desktop.
ReScript FFI example bindings for ethers.
@module("ethers") external decodeBase58Unsafe: string => bigint = "decodeBase58"
@get external code: Js.Exn.t => string = "code"
@get external argument: Js.Exn.t => string = "argument"
@get external value: Js.Exn.t => string = "value"
@get external shortMessage: Js.Exn.t => string = "shortMessage"
type decodeBase58Error =
| UnknownError
| InputError({
code: string,
argument: string,
value: string,
shortMessage: string,
})
let decodeBase58 = s => {
try {
Ok(decodeBase58Unsafe(s))
} catch {
| Js.Exn.Error(err) =>
Error(
InputError({
code: code(err),
argument: argument(err),
value: value(err),
shortMessage: shortMessage(err),
}),
)
| _ => Error(UnknownError)
}
}
let decodeBase58Unsafe: string => bigint
type decodeBase58Error =
| UnknownError
| InputError({
code: string,
argument: string,
value: string,
shortMessage: string,
})
let decodeBase58: string => result<bigint, decodeBase58Error>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment