Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Errors when using connectMetamask with colonyJS #14

Closed
ryanchristo opened this issue Aug 16, 2018 · 4 comments
Closed

Errors when using connectMetamask with colonyJS #14

ryanchristo opened this issue Aug 16, 2018 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@ryanchristo
Copy link
Contributor

ryanchristo commented Aug 16, 2018

Description

When calling colonyJS methods using the connectMetamask example while connected to the rinkeby network, the following error is thrown:

(node:59025) UnhandledPromiseRejectionWarning: Error: invalid hexlify value
    at Object.throwError (/Users/Admin/Workspace/projects/colony/colonyStarter/builds/colony-starter-basic/node_modules/ethers/utils/errors.js:74:17)
    at Object.hexlify (/Users/Admin/Workspace/projects/colony/colonyStarter/builds/colony-starter-basic/node_modules/ethers/utils/convert.js:167:12)
    at checkTransaction (/Users/Admin/Workspace/projects/colony/colonyStarter/builds/colony-starter-basic/node_modules/ethers/providers/provider.js:241:40)
    at /Users/Admin/Workspace/projects/colony/colonyStarter/builds/colony-starter-basic/node_modules/ethers/providers/provider.js:849:48
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)
(node:59025) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:59025) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The transactions are going through and they are verifiable on Etherscan but node-metamask is not receiving the transaction receipts and the colonyJS methods are unable to complete successfully.

The error is being thrown from the installed ethers package. The payload values are being returned from Metamask as strings, which ethers is unable to convert to hex values. I am not sure if this is an issue with ethers, Metamask or node-metamask or whether it can solved with colonyJS.

Also, I am able to successfully run colonyJS methods when using Metamask while connected to a local test network. I am only receiving this error when using Metamask while connected to Rinkeby.

Steps to Reproduce

Add the following code to example/connectMetamask.js just before disconnecting metamask:

  // Create a new ERC20 token
  const tokenAddress = await networkClient.createToken({
    name: 'Token',
    symbol: 'TKN',
  });

  // Check out the logs to see our new the address of our new token
  console.log('Token Address: ' + tokenAddress);

Make sure metamask is connected to Rinkeby and run the example:

yarn metamask

Related Issues

JoinColony/colonyJS#243
JoinColony/colonyStarter#6

@ryanchristo ryanchristo added the bug Something isn't working label Aug 16, 2018
@ryanchristo
Copy link
Contributor Author

After further investigation, the gasPrice and value returned from getTransaction are both being returned as string types, which ethers does not accept and therefore does not hexify.

I was able to add a formatResult method to the RemoteMetamaskProvider in node-metamask and convert the values to numbers (ethers does not accept standard big number types such as those provided by bn.js or bignumber.js, it only accepts its own proprietary big number type using the utility method bigNumberify). After this, I was able to successfully run the createToken method.

I then tested the createColony method by adding the example just below createToken:

  // Create a colony with the given token
  const {
    eventData: { colonyAddress, colonyId }
  } = await networkClient.createColony.send({ tokenAddress });

  // Check out the logs to see our new colony address
  console.log('Colony Address:', colonyAddress);

  // Check out the logs to see our new colony id
  console.log('Colony ID:', colonyId);

This gave me the following error when connected to both the local test network and rinkeby:

(node:64291) UnhandledPromiseRejectionWarning: Error: not an array
    at /Users/Admin/Workspace/sandbox/colony-starter-basic/node_modules/ethers/providers/provider.js:78:44
    at /Users/Admin/Workspace/sandbox/colony-starter-basic/node_modules/ethers/providers/provider.js:881:37
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)

After further investigation, the eth_filter method is returning a single object in the log when it should be returning an array of objects. eth_filter successfully returns an array before createToken but returns an object (a single transaction) after createToken.

@ryanchristo ryanchristo self-assigned this Aug 17, 2018
@ryanchristo ryanchristo changed the title Ethers error when using connectMetamask with rinkeby Errors when using connectMetamask with colonyJS methods Aug 17, 2018
@ryanchristo
Copy link
Contributor Author

ryanchristo commented Aug 17, 2018

I added a condition to the above mentioned formatResult method in node-metamask that returns the result in an array if the result has a logIndex value, which solved the not an array error that was being thrown from ethers but the example only succeeds intermittently. Continuing to investigate.

@ryanchristo ryanchristo changed the title Errors when using connectMetamask with colonyJS methods Errors when using connectMetamask with colonyJS Aug 21, 2018
@ryanchristo
Copy link
Contributor Author

ryanchristo commented Aug 22, 2018

I think I found the issue with intermittent success, which was being caused byMetaMaskConnector in node-metamask sending the wrong result for the given request. All errors in this issue should be resolved with the next release once JoinColony/node-metamask#8 is merged and published.

@ryanchristo
Copy link
Contributor Author

ryanchristo commented Aug 23, 2018

Resolved with node-metamask version 1.1.1 and colony-starter-basic version 1.0.0-beta.1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant