CirclesUBI / metatx-client

A frontend metatx library for generating metatx hashes on a client
GNU Affero General Public License v3.0
3 stars 0 forks source link

this.relayContract.getNonce(senderAddress) fails with [TypeError: undefined is not an object (evaluating 'input.startsWith')] #2

Open edzillion opened 5 years ago

edzillion commented 5 years ago
// generateMetaTxHash()
// _getNonce()
this.relayContract i {
  "_events": Array [],
  "addToWhitelist": [Function anonymous],
  "addToWhitelist(address[])": [Function anonymous],
  "address": "0xEc0F9905ae534d4a15d55c687045338Ed5e8fe78",
  "addressPromise": R {
    "": 56,
    "_result": "0xEc0F9905ae534d4a15d55c687045338Ed5e8fe78",
    "_state": 1,
    "_subscribers": Array [],
  },
  "estimate": Object {
    "addToWhitelist": [Function anonymous],
    "addToWhitelist(address[])": [Function anonymous],
    "getAddress": [Function anonymous],
    "getAddress(bytes)": [Function anonymous],
    "getNonce": [Function anonymous],
    "getNonce(address)": [Function anonymous],
    "relayMetaTx": [Function anonymous],
    "relayMetaTx(uint8,bytes32,bytes32,address,bytes,address)": [Function anonymous],
    "removeFromWhitelist": [Function anonymous],
    "removeFromWhitelist(address[])": [Function anonymous],
    "whitelist": [Function anonymous],
    "whitelist(address,address)": [Function anonymous],
  },
  "filters": Object {},
  "functions": Object {
    "addToWhitelist": [Function anonymous],
    "addToWhitelist(address[])": [Function anonymous],
    "getAddress": [Function anonymous],
    "getAddress(bytes)": [Function anonymous],
    "getNonce": [Function anonymous],
    "getNonce(address)": [Function anonymous],
    "relayMetaTx": [Function anonymous],
    "relayMetaTx(uint8,bytes32,bytes32,address,bytes,address)": [Function anonymous],
    "removeFromWhitelist": [Function anonymous],
    "removeFromWhitelist(address[])": [Function anonymous],
    "whitelist": [Function anonymous],
    "whitelist(address,address)": [Function anonymous],
  },
  "getAddress": [Function anonymous],
  "getAddress(bytes)": [Function anonymous],
  "getNonce": [Function anonymous],
  "getNonce(address)": [Function anonymous],
  "interface": e {
    "abi": Array [
      Object {
        "constant": true,
        "inputs": Array [
          Object {
            "name": "",
            "type": "address",
          },
          Object {
            "name": "",
            "type": "address",
          },
        ],
        "name": "whitelist",
        "outputs": Array [
          Object {
            "name": "",
            "type": "bool",
          },
        ],
        "payable": false,
        "signature": "0xb092145e",
        "stateMutability": "view",
        "type": "function",
      },
      Object {
        "constant": false,
        "inputs": Array [
          Object {
            "name": "sigV",
            "type": "uint8",
          },
          Object {
            "name": "sigR",
            "type": "bytes32",
          },
          Object {
            "name": "sigS",
            "type": "bytes32",
          },
          Object {
            "name": "destination",
            "type": "address",
          },
          Object {
            "name": "data",
            "type": "bytes",
          },
          Object {
            "name": "listOwner",
            "type": "address",
          },
        ],
        "name": "relayMetaTx",
        "outputs": Array [],
        "payable": false,
        "signature": "0xc3f44c0a",
        "stateMutability": "nonpayable",
        "type": "function",
      },
      Object {
        "constant": true,
        "inputs": Array [
          Object {
            "name": "b",
            "type": "bytes",
          },
        ],
        "name": "getAddress",
        "outputs": Array [
          Object {
            "name": "a",
            "type": "address",
          },
        ],
        "payable": false,
        "signature": "0xc47cf5de",
        "stateMutability": "pure",
        "type": "function",
      },
      Object {
        "constant": true,
        "inputs": Array [
          Object {
            "name": "add",
            "type": "address",
          },
        ],
        "name": "getNonce",
        "outputs": Array [
          Object {
            "name": "",
            "type": "uint256",
          },
        ],
        "payable": false,
        "signature": "0x2d0335ab",
        "stateMutability": "view",
        "type": "function",
      },
      Object {
        "constant": false,
        "inputs": Array [
          Object {
            "name": "sendersToUpdate",
            "type": "address[]",
          },
        ],
        "name": "addToWhitelist",
        "outputs": Array [],
        "payable": false,
        "signature": "0x7f649783",
        "stateMutability": "nonpayable",
        "type": "function",
      },
      Object {
        "constant": false,
        "inputs": Array [
          Object {
            "name": "sendersToUpdate",
            "type": "address[]",
          },
        ],
        "name": "removeFromWhitelist",
        "outputs": Array [],
        "payable": false,
        "signature": "0x548db174",
        "stateMutability": "nonpayable",
        "type": "function",
      },
    ],
    "deployFunction": t {
      "inputs": Array [],
      "payable": true,
    },
    "events": Object {},
    "functions": Object {
      "addToWhitelist": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "sendersToUpdate",
            "type": "address[]",
          },
        ],
        "name": "addToWhitelist",
        "outputs": Array [],
        "payable": false,
        "sighash": "0x7f649783",
        "signature": "addToWhitelist(address[])",
        "type": "transaction",
      },
      "addToWhitelist(address[])": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "sendersToUpdate",
            "type": "address[]",
          },
        ],
        "name": "addToWhitelist",
        "outputs": Array [],
        "payable": false,
        "sighash": "0x7f649783",
        "signature": "addToWhitelist(address[])",
        "type": "transaction",
      },
      "getAddress": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "b",
            "type": "bytes",
          },
        ],
        "name": "getAddress",
        "outputs": Array [
          Object {
            "name": "a",
            "type": "address",
          },
        ],
        "payable": false,
        "sighash": "0xc47cf5de",
        "signature": "getAddress(bytes)",
        "type": "call",
      },
      "getAddress(bytes)": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "b",
            "type": "bytes",
          },
        ],
        "name": "getAddress",
        "outputs": Array [
          Object {
            "name": "a",
            "type": "address",
          },
        ],
        "payable": false,
        "sighash": "0xc47cf5de",
        "signature": "getAddress(bytes)",
        "type": "call",
      },
      "getNonce": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "add",
            "type": "address",
          },
        ],
        "name": "getNonce",
        "outputs": Array [
          Object {
            "name": "",
            "type": "uint256",
          },
        ],
        "payable": false,
        "sighash": "0x2d0335ab",
        "signature": "getNonce(address)",
        "type": "call",
      },
      "getNonce(address)": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "add",
            "type": "address",
          },
        ],
        "name": "getNonce",
        "outputs": Array [
          Object {
            "name": "",
            "type": "uint256",
          },
        ],
        "payable": false,
        "sighash": "0x2d0335ab",
        "signature": "getNonce(address)",
        "type": "call",
      },
      "relayMetaTx": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "sigV",
            "type": "uint8",
          },
          Object {
            "name": "sigR",
            "type": "bytes32",
          },
          Object {
            "name": "sigS",
            "type": "bytes32",
          },
          Object {
            "name": "destination",
            "type": "address",
          },
          Object {
            "name": "data",
            "type": "bytes",
          },
          Object {
            "name": "listOwner",
            "type": "address",
          },
        ],
        "name": "relayMetaTx",
        "outputs": Array [],
        "payable": false,
        "sighash": "0xc3f44c0a",
        "signature": "relayMetaTx(uint8,bytes32,bytes32,address,bytes,address)",
        "type": "transaction",
      },
      "relayMetaTx(uint8,bytes32,bytes32,address,bytes,address)": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "sigV",
            "type": "uint8",
          },
          Object {
            "name": "sigR",
            "type": "bytes32",
          },
          Object {
            "name": "sigS",
            "type": "bytes32",
          },
          Object {
            "name": "destination",
            "type": "address",
          },
          Object {
            "name": "data",
            "type": "bytes",
          },
          Object {
            "name": "listOwner",
            "type": "address",
          },
        ],
        "name": "relayMetaTx",
        "outputs": Array [],
        "payable": false,
        "sighash": "0xc3f44c0a",
        "signature": "relayMetaTx(uint8,bytes32,bytes32,address,bytes,address)",
        "type": "transaction",
      },
      "removeFromWhitelist": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "sendersToUpdate",
            "type": "address[]",
          },
        ],
        "name": "removeFromWhitelist",
        "outputs": Array [],
        "payable": false,
        "sighash": "0x548db174",
        "signature": "removeFromWhitelist(address[])",
        "type": "transaction",
      },
      "removeFromWhitelist(address[])": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "sendersToUpdate",
            "type": "address[]",
          },
        ],
        "name": "removeFromWhitelist",
        "outputs": Array [],
        "payable": false,
        "sighash": "0x548db174",
        "signature": "removeFromWhitelist(address[])",
        "type": "transaction",
      },
      "whitelist": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "",
            "type": "address",
          },
          Object {
            "name": "",
            "type": "address",
          },
        ],
        "name": "whitelist",
        "outputs": Array [
          Object {
            "name": "",
            "type": "bool",
          },
        ],
        "payable": false,
        "sighash": "0xb092145e",
        "signature": "whitelist(address,address)",
        "type": "call",
      },
      "whitelist(address,address)": t {
        "gas": undefined,
        "inputs": Array [
          Object {
            "name": "",
            "type": "address",
          },
          Object {
            "name": "",
            "type": "address",
          },
        ],
        "name": "whitelist",
        "outputs": Array [
          Object {
            "name": "",
            "type": "bool",
          },
        ],
        "payable": false,
        "sighash": "0xb092145e",
        "signature": "whitelist(address,address)",
        "type": "call",
      },
    },
  },
  "provider": o {
    "_balances": Object {},
    "_emitted": Object {
      "block": -2,
    },
    "_events": Array [],
    "_fastQueryDate": 0,
    "_lastBlockNumber": -2,
    "_pollingInterval": 4000,
    "connection": Object {
      "url": "192.168.178.27:8545",
    },
    "ready": R {
      "": 49,
      "_onerror": null,
      "_result": [Error: invalid response - 0],
      "_state": 2,
      "_subscribers": Array [],
    },
  },
  "relayMetaTx": [Function anonymous],
  "relayMetaTx(uint8,bytes32,bytes32,address,bytes,address)": [Function anonymous],
  "removeFromWhitelist": [Function anonymous],
  "removeFromWhitelist(address[])": [Function anonymous],
  "signer": null,
  "whitelist": [Function anonymous],
  "whitelist(address,address)": [Function anonymous],
}
// this.relayContract.getNonce(senderAddress)
[ERROR] 00:10.983 Auth Saga [TypeError: undefined is not an object (evaluating 'input.startsWith')]
edzillion commented 5 years ago

Seems like it's an issue connecting to ganache: Failed to connect to /127.0.0.1:8545

utilities.pad = (input) => {
  console.log('input call', JSON.stringify(input))  
  if (input.startsWith('0x')) {

input call {"line":259178,"column":36,"sourceURL":"http://192.168.178.27:19001/node_modules/expo/AppEntry.bundle?platform=android&dev=true&minify=false&hot=false&assetPlugin=E%3A%5Cdev%5Ccircles%5Ccircles-mobile%5Cnode_modules%5Cexpo%5Ctools%5ChashAssetFiles.js","statusCode":0,"responseText":"Failed to connect to /127.0.0.1:8545"}

edzillion commented 5 years ago

It seems to be something to do with the provider not working right (I removed the RPC_URL to use the default url)

export const customHttpProvider = new ethers.providers.JsonRpcProvider()

When I try to run a simple method on the provider it fails:

const latestBlock = await provider.getBlockNumber()
const accounts = await provider.listAccounts()

Both respond with Error: invalid response - 0

If I put that in a try catch block I get a big list of random warnings with some mention of the RPC toward the top:

Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info. (Saw setTimeout with duration 120000ms)
- node_modules\expo\build\environment\logging.js:25:23 in warn
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:248:8 in setTimeout
- node_modules\ethers\dist\ethers.min.js:1:283646 in <unknown>
- node_modules\ethers\dist\shims.js:1:5963 in <unknown>
- node_modules\ethers\dist\shims.js:1:6022 in R
- node_modules\ethers\dist\ethers.min.js:1:283585 in fetchJson
- node_modules\ethers\dist\ethers.min.js:1:206210 in send
- node_modules\ethers\dist\ethers.min.js:1:206018 in listAccounts
* lib\utilities\metatx-client\index.js:46:25 in _accounts$
- node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:45:44 in tryCatch
- node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:271:30 in invoke
- node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:45:44 in tryCatch
- node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:135:28 in invoke
- node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:170:17 in <unknown>
- node_modules\ethers\dist\shims.js:1:5963 in <unknown>
- node_modules\ethers\dist\shims.js:1:6022 in R
- node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:169:27 in callInvokeWithMethodAndArg
- node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:192:38 in enqueue
- node_modules\@babel\runtime\node_modules\regenerator-runtime\runtime.js:216:8 in async
* null:null in _accounts
* lib\utilities\metatx-client\index.js:16:19 in MetaTx
* lib\utilities\blockchain.js:32:42 in <unknown>
- node_modules\metro\src\lib\polyfills\require.js:292:12 in loadModuleImplementation
* lib\sagas\AuthSaga.js:4:0 in <unknown>
- node_modules\metro\src\lib\polyfills\require.js:292:12 in loadModuleImplementation
* lib\sagas\index.js:3:0 in <unknown>
- node_modules\metro\src\lib\polyfills\require.js:292:12 in loadModuleImplementation
* lib\store\index.js:3:0 in <unknown>
- node_modules\metro\src\lib\polyfills\require.js:292:12 in loadModuleImplementation
* App.js:6:0 in <unknown>
- node_modules\metro\src\lib\polyfills\require.js:292:12 in loadModuleImplementation
- node_modules\expo\AppEntry.js:2:0 in <unknown>
- node_modules\metro\src\lib\polyfills\require.js:292:12 in loadModuleImplementation
- node_modules\metro\src\lib\polyfills\require.js:179:45 in guardedLoadModule
* null:null in global code

The provider object itself has the _lastBlockNumber set to -2:

{"ready":{"":17,"_subscribers":[{"":18,"_subscribers":[]},null,null],"_onerror":null},"_lastBlockNumber":-2,"_balances":{},"_events":[],"_pollingInterval":4000,"_emitted":{"block":-2},"_fastQueryDate":0,"connection":{"url":"http://localhost:8545"}}

edzillion commented 5 years ago

If I connect to ganache using a cli the listAccounts() call works fine.

also the provider object looks different:

JsonRpcProvider {
  ready:
   Promise {
     <pending>,
     domain:
      Domain {
        domain: null,
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        members: [] } },
  _lastBlockNumber: -2,
  _balances: {},
  _events: [],
  _pollingInterval: 4000,
  _emitted: { block: -2 },
  _fastQueryDate: 0,
  connection: { url: 'http://localhost:8545' } }
edzillion commented 5 years ago

It seems for the provider to work, that the ready promise needs to resolve to something like this:

{ chainId: 5777, name: 'unknown' }, domain: [...]

I am guessing this promise is not resolving; if I try

await provider.ready

It never returns.

edzillion commented 5 years ago

Ok so it seems like no matter what I use as the RPC_URL I still get the same object returned (with lots more subscribers), so I am pretty sure it never establishes a proper connection.

export const customHttpProvider = new ethers.providers.JsonRpcProvider('1.1.1.1')

provider {"ready":{"":49,"_subscribers":[{"":50,"_subscribers":[]},null,null],"_onerror":null},"_lastBlockNumber":-2,"_balances":{},"_events":[],"_pollingInterval":4000,"_emitted":{"block":-2},"_fastQueryDate":0,"connection":{"url":"1.1.1.1"}}

edzillion commented 5 years ago

Other things I have tried:

no change

shkfnly commented 5 years ago

Don't install metatx-client as a package yet its not ready

edzillion commented 5 years ago

Don't install metatx-client as a package yet its not ready

I am using it from the submodule lib\utilities\metatx-client