Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

general - Unable to use 0x libraries: 'cannot read property slice of undefined' #2041

Closed
the-jackalope opened this issue Aug 7, 2019 · 6 comments
Assignees

Comments

@the-jackalope
Copy link

Doing almost anything that makes requests to the network with the latest release of various 0x libraries results in the same error. The easiest to demonstrate is the contract-wrappers repo - I expect to retrieve a public address's ZRX token balance on the mainnet with the following code:

const Web3 = require('web3');
const provider = new Web3.providers.HttpProvider('http://provider-url-here');

const { ContractWrappers } = require('@0x/contract-wrappers');
const  contractWrappers = new ContractWrappers(provider, { networkId: 1 });

contractWrappers.erc20Token.getBalanceAsync('ZRX_ADDRESS_HERE', 'ANY_ETHEREUM_ADDRESS_HERE').then(console.log).catch(console.error)

Which consistently yield the following error:

> TypeError: Cannot read property 'slice' of undefined
    at Function.BaseContract._throwIfRevertWithReasonCallResult (/Users/johngcook/Developer/fetch/desktop/node_modules/@0x/base-contract/lib/src/index.js:169:27)
    at ERC20TokenContract.<anonymous> (/Users/johngcook/Developer/fetch/desktop/node_modules/@0x/contract-wrappers/node_modules/@0x/abi-gen-wrappers/lib/src/generated-wrappers/erc20_token.js:428:62)
    at step (/Users/johngcook/Developer/fetch/desktop/node_modules/@0x/contract-wrappers/node_modules/@0x/abi-gen-wrappers/lib/src/generated-wrappers/erc20_token.js:56:23)
    at Object.next (/Users/johngcook/Developer/fetch/desktop/node_modules/@0x/contract-wrappers/node_modules/@0x/abi-gen-wrappers/lib/src/generated-wrappers/erc20_token.js:37:53)
    at fulfilled (/Users/johngcook/Developer/fetch/desktop/node_modules/@0x/contract-wrappers/node_modules/@0x/abi-gen-wrappers/lib/src/generated-wrappers/erc20_token.js:28:58)
    at process.internalTickCallback (internal/process/next_tick.js:77:7)

Whereas I expect to get the address's token balance. I don't believe it to be an issue with the provider as I can instantiate a Web3 instance with the provider and use it to correctly query the address's ETH balance.

@0x/contract-wrappers: 10.1.0
web3: 1.0.0-beta.55

@DonGambas
Copy link

I'm experiencing the same exact issue.

@fabioberger
Copy link
Contributor

fabioberger commented Aug 13, 2019

Thanks for the report @the-jackalope @DonGambas. I just tried to reproducing the issue on the latest release, and it works as expected:

const Web3 = require('web3');
const provider = new Web3.providers.HttpProvider('https://mainnet.0x.org/');

const { ERC20TokenContract } = require('@0x/contract-wrappers');

const erc20 = new ERC20TokenContract('0xe41d2489571d322189246dafa5ebde1f4699f498', provider)

erc20.balanceOf.callAsync('0xBa12F51a5EeCB92bB366e9Bf36e11024199F35A1').then(console.log).catch(console.error)

Since this was a major version bump for the library and introduced quite a big change to the public interface, we put together this upgrade guide: #2040

@DonGambas
Copy link

@fabioberger thanks for the response, I initially installed the packaged with npm, when I installed them with yarn there was no issue 🤦‍♂

I have one additional question re: the upgrade guide. All of the order validation functions got moved to the order-utils package. It would be helpful to see an example of how to use the order validation utils in the order-utils package in particular how to set up the exchangeTradeEmulator.

@fabioberger
Copy link
Contributor

@DonGambas glad you were able to get that sorted.

Which order validation method are you using and what precisely is your use-case?

@stale
Copy link

stale bot commented Sep 15, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 15, 2019
@stale
Copy link

stale bot commented Oct 15, 2019

This issue has been automatically closed because no activity occured in 7 days after being marked as stale. If it's still relevant - feel free to reopen. Thank you for your contributions.

@stale stale bot closed this as completed Oct 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants