3

I wrote a contract to enable registration of a name. As an example, one of the functions takes in a name as a string, then outputs information on the registration of the name (name, registrant, last time that name was updated, registration ID, and whether or not it's currently registered). I can call the function in the Truffle console just fine, but keep getting an Uncaught TypeError when using the web3 JavaScript API to call the same function and I don't know why.

Here's what it looks like in the Truffle console:

Image 1 (Truffle)

When I try to call this same function in a JavaScript console in Chrome (using React to develop a front-end), I get this error and I'm not sure why:

inpage.js:7928 Uncaught TypeError: Cannot read property 'match' of undefined

Here's an image showing the function I'm calling with the error:

Image 2 (JavaScript console)

The nameRegContract object was created like this for reference:

var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
var nameRegABI = [... ABI ...];
var nameRegAddress = '0x23fa6b40bdf47a6a41feb62077dab84213daa624';
var nameRegContract = web3.eth.contract(nameRegABI).at(nameRegAddress);

Wondering if anyone knows why I'm getting this error/if I'm using the web3 JavaScript API incorrectly?

4
  • 1
    I don't knwo nothing about Truffle, but try to check the ABI and the address try with this: '0x23Fa6b40Bdf47a6A41FEB62077dAB84213DaA624'
    – Gawey
    Commented Jun 1, 2017 at 8:03
  • That doesn't work unfortunately. I don't think the issue is with the ABI/address because all of the contract's functions appear when I call just the nameRegContract object by itself (as seen in the image), but I could be wrong
    – jberm
    Commented Jun 1, 2017 at 9:43
  • getName Info is a function of the contract? and what is the properly 'match' is there something like this in the code?
    – Gawey
    Commented Jun 1, 2017 at 9:46
  • 1
    You were right actually! I had copied the wrong ABI! Got it to work, thank you!
    – jberm
    Commented Jun 1, 2017 at 9:56

1 Answer 1

5

Thank you to Gawey in the comments for the answer. The problem was that I used the wrong ABI to create the contract object while in the JavaScript console. To get the correct ABI, I went into the file Truffle created of the compiled contract and copied the ABI from there. To get the incorrect ABI, I had used the Truffle console and typed contractName.ABI, which gave me all of the contract's functions, however, that ABI didn't specify each function's inputs and outputs, which resulted in the TypeError.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.