Skip to content

[JST-11] SDK cannot be used with ethers.js v6 #41

@joewagner

Description

@joewagner

context

A user reported this bug in Discord here https://discord.com/channels/592843512312102924/1077277654132215960

initial report

The initial report is from a user running the basic sdk example from the docs:

import { Database, helpers } from "@tableland/sdk"
import { Wallet } from "ethers"
import * as dotenv from "dotenv"
dotenv.config()

async function main() {
    const privateKey: any = process.env.PRIVATE_KEY
    const rpc: any = process.env.RPC_URL
    
    const wallet = new Wallet(privateKey);
    const provider: any = helpers.getDefaultProvider(rpc)
    const signer: any = wallet.connect(provider);    
    interface Schema {
        id: number;
        name: string;
    }
    
    const db = new Database<Schema>({ signer: signer })
    
    const prefix: string = "my_sdk_table";
    
    const { meta: create } = await db
        .prepare(`CREATE TABLE ${prefix} (id integer primary key, name text);`)
        .run();
    
    console.log(create.txn?.name)
}

main();

This results in: Error: RUN_ERROR: signer.getChainId is not a function

details

Ethers.js v6 was recently released https://docs.ethers.org/v6
With this release the signer interface no longer has the getChainId method. The chainId is potentially available elsewhere within the ethers v6 signer, but we might want to decide if there's a more robust way to get the chainId.
The v3 SDK had the requirement that a specific network had been connected to, which made this problem a little easier.

ideas for a solution

  • We could potentially try to sniff out what kind of interface the passed in signer supports. The downside I see here is that this could be cumbersome.
  • We could determine the chainId from the query. I think this makes sense, but I'd have to dive into implementation to be sure.

JST-11

Metadata

Metadata

Assignees

Labels

linearSync issue with linear

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions