ethers.js: Discussion: should slice (and other missing ops) be shimmed? (e.g. slice in ReactNative)

I’m creating a ReactNative based app using this lib. When I run in iOS simulator, eveything goes fine. But when I run in my real Android device I’m having the following error:

[TypeError: undefined is not a function (evaluating 'data.slice(offset + junkLength, offset + 32)')]

It happens when I’m trying to execute the following piece of code after loading the wallet with my private key:

const updateBalance = () => (dispatch) => {
    const { contract, wallet } = store.getState().wallet;
    contract.functions.balanceOf(wallet.getAddress())
        .then(({ balance }) => dispatch({ type: UPDATE_BALANCE, payload: balance }));
}

Looking at the lib source, I figured out the place where this error can be located at in this: https://github.com/ethers-io/ethers.js/blob/fb65772dd68d5ec5271ff2171560b306f013d09d/contracts/interface.js#L73

Do you have any idea of what might be happening?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Heya! it does for React too. I’ve added the automatic slice and a few other features that often missing in older environments, like React.

Can you try updating to the latest version and remove your shims to see if it works now, out of the box?

It passes all the PhantomJS tests sans shims, so I’m hoping it does for React too. 😃