scrtlabs / secret.js

The JavaScript SDK for Secret Network
https://secretjs.scrt.network
MIT License
74 stars 36 forks source link

Wallet and SecretNetworkClient from "secretjs" are undefined #82

Open noahNewton opened 2 years ago

noahNewton commented 2 years ago

Our react native app is trying to import the Wallet class and SecretNetworkClient class and use them to make a transaction as per this documentation: https://secretjs.scrt.network/#broadcasting-transactions

The error I am getting is "TypeError: Cannot read properties of undefined (reading 'Wallet')" when I try to instantiate the object using our mnemonic or when using your mnemonic in the aforementioned documentation.

It is very strange because when I hover over "Wallet" in VScode it will display the comment and @params that are present in your secretjs/dist/wallet_*.js/ts files as if it is indeed imported and is defined.. so perhaps there is an issue in your inheritance model on your end?

We have version ^1.2.0-beta.58 installed

Let me know if you need any more information, thanks in advance for taking a look into this!

assafmo commented 2 years ago

Hi, can you share a repo for me to play with or a code example?

noahNewton commented 2 years ago

Hi, can you share a repo for me to play with or a code example?

Unfortunately I cannot because it's a proprietary repo, but there is a new error, all I am doing is following the simple code example here: https://github.com/scrtlabs/secret.js#sending-queries

This code: `import { SecretNetworkClient } from "secretjs";

// To create a readonly secret.js client, just pass in a gRPC-web endpoint const secretjs = await SecretNetworkClient.create({ grpcWebUrl: "https://grpc-web.azure-api.net", chainId: "secret-4", });

const { balance: { amount }, } = await secretjs.query.bank.balance({ address: "secret1ap26qrlp8mcq2pg6r47w43l0y8zkqm8a450s03", denom: "uscrt", });

console.log(I have ${amount / 1e6} SCRT!);`

Is throwing this error: Error: Requiring module "node_modules/secretjs/dist/browser.js", which threw an exception: TypeError: Cannot convert a BigInt value to a number

assafmo commented 2 years ago

Can you try converting amount / 1e6 into Number(amount) / 1e6?

noahNewton commented 2 years ago

I tried that but it doesn't help because the issue is importing, the error thrown is:

Error: Requiring module "node_modules/secretjs/dist/browser.js", which threw an exception: TypeError: Cannot convert a BigInt value to a number

Which I believe is an error in a file on your end where there is an attempt to convert a BitInt to a Number

assafmo commented 2 years ago

How are you running/compiling this? Using webpack/esbuild/vite? What version of node.js?

assafmo commented 2 years ago

Can I get access to the code if I sign an NDA? This seems like an issue with secret.js and I want to iterate faster to solve it.

noahNewton commented 2 years ago

How are you running/compiling this? Using webpack/esbuild/vite? What version of node.js?

It's a react-native app, so we're doing rn-nodeify in order to get some other dependencies to work, and it's interesting that secretjs 0.17.5 works, just not the latest version, but we want the latest version.

Can I get access to the code if I sign an NDA? This seems like an issue with secret.js and I want to iterate faster to solve it.

I will ask the team lead, or maybe we can coordinate a screenshare session or something

assafmo commented 2 years ago

Can you help me set up an empty project? Just to try and reproduce this on my machine.

noahNewton commented 2 years ago

Can you help me set up an empty project? Just to try and reproduce this on my machine.

Hi Assaf, thanks for your attentiveness to my issue, I really appreciate it.

I've set up a barebones react-native project, and all I did was install the latest version of secretjs and try to do the example in the docs, the code for this can be found here: https://github.com/noahNewton/rn-secretjs-test

I am still faced with the same error: "TypeError: Conversion from 'BigInt' to 'number' is not allowed."

assafmo commented 2 years ago

Mmmm it just works for me... What version of node.js are you using?

image

noahNewton commented 2 years ago

Mmmm it just works for me... What version of node.js are you using?

My machine is running node version v16.13.2 and the project is react-native-cli v2.0.1 and react-native 0.67.3

This is very strange, is it possible the Xcode/iOS simulator could be causing this issue? Because it looks like the above is not using react-native?

noahNewton commented 2 years ago

What is your environment like? Node version? Can you try running it in the xcode ios simulator?

assafmo commented 2 years ago

I'll try, I don't have xcode but I think I have a lead

noahNewton commented 2 years ago

Any update @assafmo? Or need any more info?

assafmo commented 2 years ago

Hi, can you try to use secretjs@1.2.0-beta.66?

noahNewton commented 2 years ago

Hi Assaf, sorry for the late response, I have installed version 1.2.0-beta.66 and it appears SecretJS is still not working for ios, same error as before as you can see in the screenshot:

Screen Shot 2022-04-28 at 7 02 49 AM
assafmo commented 2 years ago

Hi, can you please try secretjs@1.3.0-beta.4?

noahNewton commented 2 years ago
Screen Shot 2022-06-06 at 6 29 36 AM Screen Shot 2022-06-06 at 6 29 56 AM

Hi Assaf, does not appear to have been fixed with the latest version. Please see the screenshots of the errors

assafmo commented 1 year ago

v1.5 now supports react-native, please check this out https://github.com/scrtlabs/react-native-secretjs