2

I keep encountering an error saying invalid address. Why is this?

const Web3 = require('web3');
const contract = require('truffle-contract');

const MyContract = require('../build/contracts/MyContract.json'

web3 = new Web3.providers.HttpProvider('http://localhost:8545');

var Contract = contract(MyContract);

Contract.setProvider(web3);

Contract.new()
    .then(instance => {
    c = instance;
    return c.getCreator();
})
   .catch(error => {
    console.log(`${error}`);
})

MyContract.json:

{
 "contract_name": "MyContract",
 "abi": [
{
  "constant": true,
  "inputs": [],
  "name": "getCreator",
  "outputs": [
    {
      "name": "",
      "type": "address"
    }
  ],
  "payable": false,
  "type": "function"
},
{
  "constant": true,
  "inputs": [],
  "name": "getContractAddress",
  "outputs": [
    {
      "name": "",
      "type": "address"
    }
  ],
  "payable": false,
  "type": "function"
},
{
  "constant": false,
  "inputs": [
    {
      "name": "newMessage",
      "type": "string"
    }
  ],
  "name": "setMessage",
  "outputs": [],
  "payable": false,
  "type": "function"
},
{
  "constant": true,
  "inputs": [],
  "name": "getLastCaller",
  "outputs": [
    {
      "name": "",
      "type": "address"
    }
  ],
  "payable": false,
  "type": "function"
},
{
  "constant": true,
  "inputs": [],
  "name": "getMessage",
  "outputs": [
    {
      "name": "",
      "type": "string"
    }
  ],
  "payable": false,
  "type": "function"
},
{
  "inputs": [],
  "payable": false,
  "type": "constructor"
}
  ],
 "unlinked_binary": "0x6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a031617905560408051908101604052600b81527f68656c6c6f20776f726c6400000000000000000000000000000000000000000060208201526002908051610072929160200190610079565b505b610119565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100ba57805160ff19168380011785556100e7565b828001600101855582156100e7579182015b828111156100e75782518255916020019190600101906100cc565b5b506100f49291506100f8565b5090565b61011691905b808211156100f457600081556001016100fe565b5090565b90565b6103c0806101286000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630ee2cb10811461006957806332a2c5d014610098578063368b8772146100c7578063880b36e71461011a578063ce6d41de14610149575b600080fd5b341561007457600080fd5b61007c6101d4565b604051600160a060020a03909116815260200160405180910390f35b34156100a357600080fd5b61007c6101e4565b604051600160a060020a03909116815260200160405180910390f35b34156100d257600080fd5b61011860046024813581810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496506101e995505050505050565b005b341561012557600080fd5b61007c610229565b604051600160a060020a03909116815260200160405180910390f35b341561015457600080fd5b61015c610239565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156101995780820151818401525b602001610180565b50505050905090810190601f1680156101c65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600054600160a060020a03165b90565b305b90565b60028180516101fc9291602001906102e2565b506001805473ffffffffffffffffffffffffffffffffffffffff191632600160a060020a03161790555b50565b600154600160a060020a03165b90565b610241610361565b60028054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102d75780601f106102ac576101008083540402835291602001916102d7565b820191906000526020600020905b8154815290600101906020018083116102ba57829003601f168201915b505050505090505b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061032357805160ff1916838001178555610350565b82800160010185558215610350579182015b82811115610350578251825591602001919060010190610335565b5b5061035d929150610373565b5090565b60206040519081016040526000815290565b6101e191905b8082111561035d5760008155600101610379565b5090565b905600a165627a7a72305820288648f994114d01cacb3c65b915c20822314d9a7ef26f4443023fd8d3fd582c0029",
"networks": {
"1511991611574": {
  "events": {},
  "links": {},
  "updated_at": 1512075083651
},
"1512085348050": {
  "events": {},
  "links": {},
  "updated_at": 1512086332107
}
 },
 "schema_version": "0.0.5",
 "updated_at": 1512086505628
}
3
  • Can you share the MyContract.json file? Commented Dec 1, 2017 at 4:27
  • @KarthikeyanThangavel Just shared Commented Dec 1, 2017 at 19:32
  • show your index.js it should be in node_modules\@ethersproject\contracts\lib\index.js
    – AngelDev
    Commented Jan 3, 2022 at 21:50

1 Answer 1

0

In your MyContract.json file address field was empty which means your contract was not deployed properly. Make sure your contract was deployed and the address of the contract was updated in the JSON file.

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.