Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release / Debug build generated json-rpc calls are different #2501

Closed
ungaro opened this issue Mar 14, 2019 · 5 comments
Closed

Release / Debug build generated json-rpc calls are different #2501

ungaro opened this issue Mar 14, 2019 · 5 comments

Comments

@ungaro
Copy link

ungaro commented Mar 14, 2019

Description

I'm trying to make simple web3 calls in React Native with web3.js, but generated json-rpc calls are different between release / debug builds - IOS/Xcode.

Expected behavior

    const web3 = new Web3(`https://ropsten.infura.io/${Config.INFURA_API_KEY}`);

    return new Promise((resolve, reject) => {      
            web3.eth.getBalance(walletAddress, (error, weiBalance) => {
      
              if (error) {
                console.error;
                reject(error);
              }
      
              const balance = weiBalance / Math.pow(10, 18);
              console.log("================BALANCE================");
              console.log(balance);
      
              resolve(balance);
            });
          });

should return balance.
In Debug build, there is no problem.

Actual behavior

In Release build, it fails with Node error: {"code":-32600,"message":"invalid json request"}

i've inspected that in my release build the json -rpc request becomes like this:

{"jsonrpc":"2.0","id":1,"method":{"jsonrpc":"2.0","id":0,"method":"eth_getBalance","params":["0xe1f42aa9aec952f61c5d929dd0b33690faaef976","latest"]}}

whereas in debug build the json-rpc request is like this:

{"jsonrpc":"2.0","id":0,"method":"eth_getBalance","params":["0xe1f42aa9aec952f61c5d929dd0b33690faaef976","latest"]}

how can the request get nested in the release build, this i don't understand...

Versions

  • web3.js: 1.0.0-beta.48
  • browser: react native 0.59
  • ethereum node: infura
    System:
      OS: macOS High Sierra 10.13.6
      CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
      Memory: 107.09 MB / 32.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 11.3.0 - /usr/local/bin/node
      Yarn: 1.12.3 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 23, 24, 25, 26, 27, 28
        Build Tools: 26.0.3, 28.0.3
        System Images: android-23 | Google APIs Intel x86 Atom, android-24 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-26 | GooglePlay Intel x86 Atom, android-27 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5056338
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3
      react-native: 0.59.0 => 0.59.0
    npmGlobalPackages:
      create-react-native-app: 2.0.2
      react-native-cli: 2.0.1

Release build json-rpc call made by simulator/device, captured by Charles proxy.
web3_release_error

@nivida nivida added the Needs Clarification Requires additional input label Mar 14, 2019
@nivida
Copy link
Contributor

nivida commented Mar 14, 2019

Does this error also occur if you don't use the callback?

const web3 = new Web3(`https://ropsten.infura.io/${Config.INFURA_API_KEY}`);
return web3.eth.getBalance(walletAddress).then((weiBalance) => {
   return (weiBalance / Math.pow(10, 18));
});

@ungaro
Copy link
Author

ungaro commented Mar 14, 2019

Does this error also occur if you don't use the callback?

Yes, tried it, and it occurs again. Somehow, the call gets weirdly nested after method key in release builds:

{"jsonrpc":"2.0","id":1,"method":{"jsonrpc":"2.0","id":0,"method":"eth_getBalance","params":["0xe1f42aa9aec952f61c5d929dd0b33690faaef976","latest"]}}

@nivida
Copy link
Contributor

nivida commented Mar 14, 2019

I've tested it with the version beta.48 of Web3.js in a NodeJS environment and in the browser without an error thrown. This looks like a problem of react-native especially because it's nesting the JSON-RPC payload object in a weird way.

Could you create an example GitHub repository for me?

Code:

const web3 = new Web3('http://localhost:8545');
web3.eth.getBalance('0xdf09cba4cbd5902d83d4fa4e3f5e7dbfc7bd0bDD').then((weiBalance) => {
  console.log((weiBalance / Math.pow(10, 18)));
});

Request:

{"jsonrpc":"2.0","id":0,"method":"eth_getBalance","params":["0xdf09cba4cbd5902d83d4fa4e3f5e7dbfc7bd0bdc","latest"]}

Response:

{"jsonrpc":"2.0","id":0,"result":"0xc7cd587d0928fa8b8e35"}

@ungaro
Copy link
Author

ungaro commented Mar 14, 2019

@nivida I've included console.log/error statements in web3-providers/dist/web3-providers.umd.js before every sendPayload statement, here is what i've found:

In Debug build, i get this, and everything works as intended:

2019-03-15 01:24:31.243 [error][tid:com.facebook.react.JavaScript] 'sendPayload_httpprovider_umd', { jsonrpc: '2.0',
  id: 0,
  method: 'eth_getBalance',
  params: [ '0xe1f42aa9aec952f61c5d929dd0b33690faaef976', 'latest' ] }

In Release build. i strangely get this:
Notice how it first gets into sendPayload_CustomProvider_umd and nests the payload on sendPayload_httpprovider_umd

2019-03-15 01:17:10.433692+0300[48645:314312] 'sendPayload_CustomProvider_umd', { jsonrpc: '2.0',
  id: 1,
  method: 
   { jsonrpc: '2.0',
     id: 0,
     method: 'eth_getBalance',
     params: [ '0xe1f42aa9aec952f61c5d929dd0b33690faaef976', 'latest' ] },
  params: [Function] }
2019-03-15 01:17:10.434 [error][tid:com.facebook.react.JavaScript] 'sendPayload_httpprovider_umd', { jsonrpc: '2.0',
  id: 2,
  method: 
   { jsonrpc: '2.0',
     id: 1,
     method: 
      { jsonrpc: '2.0',
        id: 0,
        method: 'eth_getBalance',
        params: [ '0xe1f42aa9aec952f61c5d929dd0b33690faaef976', 'latest' ] },
     params: [Function] },
  params: [Function] }

I'm using

import './shim' // Provided by rn-nodeify --hack -- install
require('node-libs-react-native/globals');

in my start file, for react native web3 compatibility.

I'll try to upload a reproducible repo as well.

@nivida
Copy link
Contributor

nivida commented Mar 18, 2019

This is a duplication of #2484 and will be fixed with #2521

@nivida nivida closed this as completed Mar 18, 2019
@nivida nivida removed the Needs Clarification Requires additional input label Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants