Skip to content

[JST-11] SDK uses ethers v6 internally#422

Draft
joewagner wants to merge 3 commits intomainfrom
joe/bump-ethers
Draft

[JST-11] SDK uses ethers v6 internally#422
joewagner wants to merge 3 commits intomainfrom
joe/bump-ethers

Conversation

@joewagner
Copy link
Contributor

@joewagner joewagner commented Mar 9, 2023

fix tablelandnetwork/tableland-js#41
This is blocked by changes needed in evm-tableland which have to wait until Open Zeppelin supports ethers v6.

@awmuncy awmuncy changed the title SDK uses ethers v6 internally [JST-11] SDK uses ethers v6 internally Apr 7, 2023
@linear
Copy link

linear bot commented Apr 7, 2023

JST-11 SDK cannot be used with ethers.js v6

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant