balancer-sdk icon indicating copy to clipboard operation
balancer-sdk copied to clipboard

Ethers error while trying to load the sdk

Open Phenzic opened this issue 1 year ago • 3 comments

My code

import { BalancerSDK } from '@balancer-labs/sdk'

const balancer = new BalancerSDK({
  network: 5, // Mainnet
  rpcUrl: `https://eth-goerli.g.alchemy.com/v2/${process.env.ALCHEMY_API}`,
})

const { swaps } = balancer // Swaps module is abstracting SOR    

// console.log(swaps)
// // const balancer = new BalancerSDK(config);

const balance = new BalancerSDK(balancer);
const pool = await balance.pools.find(poolId);

    const main = async () => {
    const spotPrice = await pool.calcSpotPrice(
        ADDRESSES[network].DAI.address,
        ADDRESSES[network].BAL.address
        );
    console.log(spotPrice);
}

After following the procedure on the docs I keep getting the error

node:internal/modules/cjs/loader:1144
  const err = new Error(message);
              ^

Error: Cannot find module 'ethers'
Require stack:
- C:\Users\Lenovo\OneDrive - University of Lagos\Documents\Article Demo\Demo DEX Dapp\DEX\node_modules\@balancer-labs\sdk\dist\index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)        
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (C:\Users\Lenovo\OneDrive - University of Lagos\Documents\Article Demo\Demo DEX Dapp\DEX\node_modules\@balancer-labs\sdk\dist\index.js:1:317)

as though ethers is not found in the node_module for the SDK..... any solution pls image

Phenzic avatar Jan 23 '24 19:01 Phenzic

Same issue here.

youfoundron avatar Apr 26 '24 18:04 youfoundron

Same issue here.

Have you installed ethers? We have an ethersV5 dependency. #560 has some more detail that might be useful - we'll hopefully push an update to fix that next week.

johngrantuk avatar May 03 '24 09:05 johngrantuk

Yes. We ended up circumventing by using sor lib directly.

youfoundron avatar May 03 '24 17:05 youfoundron

Should be fixed in version v1.1.6-beta.18

johngrantuk avatar May 14 '24 13:05 johngrantuk