ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.88k stars 1.82k forks source link

Error when calling method on contract: TypeError: name.toLowerCase is not a function #82

Closed samuraisam closed 6 years ago

samuraisam commented 6 years ago

I am receiving the below error when trying to call the isAuthorizer('0x001702423633bF0Bdba9d357403940A6A2F860f5') function on the contract. The contract is on the ropsten network, and the address is embedded in the contract debug below. Is there a workaround for this issue, or am I doing something wrong? Strangely, in order to get the address for this contract, I have to call another contract, which works fine.

Thank you in advance for any help. This library has been great!

TypeError: name.toLowerCase is not a function
    at Object.namehash (/Users/sam/dev/bread/the-website/crowdsale-api/node_modules/ethers-utils/namehash.js:12:17)
    at FallbackProvider.resolveName (/Users/sam/dev/bread/the-website/crowdsale-api/node_modules/ethers-providers/provider.js:837:26)
    at FallbackProvider.<anonymous> (/Users/sam/dev/bread/the-website/crowdsale-api/node_modules/ethers-providers/provider.js:805:28)
    at Array.forEach (<anonymous>)
    at FallbackProvider._resolveNames (/Users/sam/dev/bread/the-website/crowdsale-api/node_modules/ethers-providers/provider.js:803:10)
    at FallbackProvider.call (/Users/sam/dev/bread/the-website/crowdsale-api/node_modules/ethers-providers/provider.js:709:17)
    at /Users/sam/dev/bread/the-website/crowdsale-api/node_modules/ethers-contracts/contract.js:123:41
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Here is the debug for the contract object:

Contract {
  address: [ '0x63Bc21c3111E887e7733F40E5a0b77b2d8c42bF6' ],
  interface:
   Interface {
     abi: [Getter],
     functions:
      { isAuthorizer: [Object],
        addAuthorizer: [Object],
        removeAuthorizer: [Object],
        authorizeAccount: [Object],
        isAuthorized: [Object] },
     events: { Authorized: [Object] },
     deployFunction: { [Function: func] inputs: [Getter] } },
  signer:
   Wallet {
     privateKey: '<redacted>',
     provider: [Getter/Setter],
     defaultGasLimit: [Getter/Setter],
     address: '0x001702423633bF0Bdba9d357403940A6A2F860f5',
     sign: [Function] },
  provider:
   FallbackProvider {
     chainId: 3,
     ensAddress: '0x112234455C3a32FD11230C42E7Bccd4A84e02010',
     name: 'ropsten',
     testnet: true,
     _events: {},
     resetEventsBlock: [Function] },
  estimate:
   { isAuthorizer: [Function],
     addAuthorizer: [Function],
     removeAuthorizer: [Function],
     authorizeAccount: [Function],
     isAuthorized: [Function] },
  functions:
   { isAuthorizer: [Function],
     addAuthorizer: [Function],
     removeAuthorizer: [Function],
     authorizeAccount: [Function],
     isAuthorized: [Function] },
  events: { Authorized: [Getter/Setter] },
  isAuthorizer: [Function],
  addAuthorizer: [Function],
  removeAuthorizer: [Function],
  authorizeAccount: [Function],
  isAuthorized: [Function],
  onauthorized: [Getter/Setter] }

Here is the contract ABI:

[
    {
      "constant": true,
      "inputs": [
        {
          "name": "_account",
          "type": "address"
        }
      ],
      "name": "isAuthorizer",
      "outputs": [
        {
          "name": "_isAuthorizer",
          "type": "bool"
        }
      ],
      "payable": false,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "name": "_newAuthorizer",
          "type": "address"
        }
      ],
      "name": "addAuthorizer",
      "outputs": [],
      "payable": false,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "name": "_bannedAuthorizer",
          "type": "address"
        }
      ],
      "name": "removeAuthorizer",
      "outputs": [],
      "payable": false,
      "type": "function"
    },
    {
      "constant": false,
      "inputs": [
        {
          "name": "_newAccount",
          "type": "address"
        }
      ],
      "name": "authorizeAccount",
      "outputs": [],
      "payable": false,
      "type": "function"
    },
    {
      "constant": true,
      "inputs": [
        {
          "name": "_account",
          "type": "address"
        }
      ],
      "name": "isAuthorized",
      "outputs": [
        {
          "name": "_authorized",
          "type": "bool"
        }
      ],
      "payable": false,
      "type": "function"
    },
    {
      "inputs": [
        {
          "name": "_initialAuthorzer",
          "type": "address"
        }
      ],
      "payable": false,
      "type": "constructor"
    },
    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": true,
          "name": "_to",
          "type": "address"
        }
      ],
      "name": "Authorized",
      "type": "event"
    }
  ]
samuraisam commented 6 years ago

Well, turns out that writing this comment helped me figure it out. The result of the previous call (to get the authorizer address) returns a tuple (as do all function calls on contracts using ethers.js) so all I had to do was unwrap the result and pass the correct data type to the contract constructor and it worked great!

ricmoo commented 6 years ago

I was almost done my response. Glad you got it. :)

I do need make better error messages...

samuraisam commented 6 years ago

Thanks! Great work on this library :)