galacticcouncil / sdk

Galactic SDK
Apache License 2.0
11 stars 14 forks source link

Following the instructions on README leads to an error #10

Closed xrash closed 9 months ago

xrash commented 1 year ago

The only thing I did was running npm install @galacticcouncil/sdk and then running this code:

// Import
const { ApiPromise, WsProvider } = require('@polkadot/api')
const { TradeRouter, PolkadotApiPoolService } = require('@galacticcouncil/sdk')

const main = async () => {

  // Initialize Polkadot API
  const wsProvider = new WsProvider('wss://rpc.basilisk.cloud');
  const api = await ApiPromise.create({ provider: wsProvider });

  // Initialize Trade Router
  const poolService = new PolkadotApiPoolService(api);
  const tradeRouter = new TradeRouter(poolService, { includeOnly: [PoolType.XYK] });

  // Do something
  const result = await tradeRouter.getAllAssets();
  console.log(result);

}

main()

I get the following error:

node:internal/fs/utils:351
    throw err;
    ^

Error: ENOENT: no such file or directory, open '<...>/node_modules/@galacticcouncil/sdk/dist/hydra_dx_wasm_bg.wasm'
    at Object.openSync (node:fs:590:3)
    at Object.readFileSync (node:fs:458:35)
    at <...>/node_modules/@galacticcouncil/sdk/dist/index.js:1:4125
    at <...>/node_modules/@galacticcouncil/sdk/dist/index.js:1:222
    at Object.<anonymous> (<...>/node_modules/@galacticcouncil/sdk/dist/index.js:3:169302)
    at Module._compile (node:internal/modules/cjs/loader:1267:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1321:10)
    at Module.load (node:internal/modules/cjs/loader:1125:32)
    at Module._load (node:internal/modules/cjs/loader:965:12)
    at Module.require (node:internal/modules/cjs/loader:1149:19) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '<...>/node_modules/@galacticcouncil/sdk/dist/hydra_dx_wasm_bg.wasm'
}

Node.js v20.1.0
Denstden commented 1 year ago

Yupp, same for me.

nohaapav commented 1 year ago

@Denstden & @xrash Wasm file is not bundled with cjs, only with esm module .. In order to use SDK in cjs (node) you have to include wasm file at project root

JackSparrowYB commented 1 year ago

@nohaapav how can we get access to the wasm file? Can you let me know the steps?

nohaapav commented 1 year ago

@nohaapav how can we get access to the wasm file? Can you let me know the steps?

I'll update doc regarding cjs usage this week.

flipchan commented 1 year ago

@nohaapav is this fixed? I get the same error

nohaapav commented 1 year ago

@flipchan Hey, it was never broken, you just have to include wasm at project root in case u using cjs .. Hopefully i can prepare some step by step doc this week ..

honglewis commented 1 year ago

@nohaapav There are four directories containing a file named 'hydra_dx_wasm_bg.wasm,' namely 'math-lbp/build,' 'math-omnipool/build,' 'math-stableswap/build,' and 'math-xyk/build.' To make my CJS project work correctly, which one of these should I copy to the project root directory?

xabsolon commented 1 year ago

When i copy the wasm file from the following directories: 'math-lbp/build,' 'math-omnipool/build,' 'math-stableswap/build,' and 'math-xyk/build.' It says O.pool_account_name is not a function.

michaeldev5 commented 1 year ago

Any updates on the documentation regarding CJS usage? @nohaapav

flipchan commented 10 months ago

@nohaapav is this fixed? I get the same error

solved it, all good for me

michaeldev5 commented 10 months ago

How did you solve it ?

flipchan commented 10 months ago

@michaeldev5 will publish the hydradx implemenation opensource soon, I'm using "@galacticcouncil/sdk": "^0.6.5", with a clean npm cache, works

nohaapav commented 9 months ago

Try to upgrade to 1.1.5 or latest .. It should work with commonjs out of the box.

michaeldev5 commented 9 months ago

It works! Many thanks @nohaapav

flipchan commented 7 months ago

@michaeldev5 seems like yarn.lock plays a prank on the new version bumps, here is an opensource implementation that ppl can use a reference: https://github.com/search?q=repo%3AXcmSend%2Fapp%20hydra&type=code

I added support for the latest version of the sdk

@nohaapav it was really nice the upgrade to v2 docs, it made my life easier, thanks