CityOfZion / neon-js

Javascript libraries that allow the applications to interact with NEO blockchain
https://docs.coz.io/neo3/neon-js/index.html
MIT License
184 stars 166 forks source link

undefined is not an object (evaluating 't.api.getBalance') when executing api.doInvoke #543

Closed nathanmukena closed 3 years ago

nathanmukena commented 4 years ago

Executing the following code is creating an issue for us when using react-native: import { api, wallet, u, nep5 } from '@cityofzion/neon-js'; . . . export const submitNeonStory = async (w, promoter_wallet, hex_wallet, hex_challenge) => { return api.doInvoke({ net: env.net, url: env.rpcEndpoint, account: w, script: { scriptHash: env.nodis_contract, operation: 'submit', args: [promoter_wallet, hex_wallet, hex_challenge] }, gas: 0 }) }

We're getting the following error: undefined is not an object (evaluating 't.api.getBalance')

snowypowers commented 4 years ago

The error is probable here. What is w that you are passing in?

nathanmukena commented 4 years ago

This is an open wallet. const w = await new wallet.Account(key)

snowypowers commented 4 years ago

are you providing the api field of the configuration object? That is the API provider for it to retrieve the balance.

nathanmukena commented 4 years ago

I am not providing the api field at the moment. Not sure I ever used this field. Can you provide an example?

snowypowers commented 4 years ago

http://cityofzion.io/neon-js/docs/en/examples/smart_contract.html#high-level

nathanmukena commented 4 years ago

Thanks. In this example, a variable is assigned to api. Can't seem to find what the value would look like. Is that supposed to be a node URL/ When reverting the neon-js version to 3.9.11, api doesn't seem to be necessary.

snowypowers commented 4 years ago

this should give a clearer picture if you are in v4.