How to create bindings to a nested module

Hi There,

A javascript library (starknet.js) that I’m trying to interop with is using a concept called “namespaces” where they bucket functionality under different submodules. What is the idiomatic pattern to create bindings to a namespaced function?

Here is an usage example from javascript that I’m looking to translate into ReScript:

import { defaultProvider, stark } from 'starknet';
const { getSelectorFromName } = stark;
console.log(getSelectorFromName("function"));

I tried to use @module(“starknet/stark”) but this didn’t work. Is stark just an object I should work with directly?

You can use @scope together with @module to specify bindings to nested functions.

e.g.:

@module("starknet") @scope("stark")
external getSelectorFromName: string => string = "getSelectorFromName"

Js.log(getSelectorFromName("function"));

Output:

import * as Starknet from "starknet";

console.log(Starknet.stark.getSelectorFromName("function"));
8 Likes