Unhandled rejection Error: This contract object doesn't have address set yet, please set an address first
Asked Answered
T

4

19

Im currently trying to use Infura to run on my machine thru Web3. When I set to run my node index.js file I get the following error:

Unhandled rejection Error: This contract object doesn't have address set yet, please set an address first.
    at Object._processExecuteArguments (/Users/Oso.Lu/cryptokitty-miner/node_modules/web3-eth-contract/src/index.js:739:15)
    at Object._executeMethod (/Users/Oso.Lu/cryptokitty-miner/node_modules/web3-eth-contract/src/index.js:760:54


var helpers = require("./helpers.js")

var Web3 = require('web3');
var Tx = require('ethereumjs-tx');

// You should be running a local Eth node or use Infura.
var web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io:443"));
var prompt = require('prompt');


var sendingAddress = "********************"  // with your sending ETH address
var pKey = "******************************"; // This will store the corresponding private key.  we'll be getting the private key for this Eth address from a command prompt


// Keep track of kitties we'll mine to avoid double-mining
var kittyArray = []

var theNonce = "";
// Gas price.   Todo: Use Eth gas station Oracle to predict gas prices
var gwei = '26'

// Track # of received
var num_requested = 0
var num_received = 0

I thought maybe the issue is running on Infura port 443.

Thersathersites answered 4/2, 2018 at 15:47 Comment(1)
This usually means you haven't set MyContract.options.address to the address returned from the contract instance after deployment. You'll need to post your complete code to confirm.Chalky
S
5

Simple solution

Voting.options.address = "0x6ee9957aef5f4073c6af71441ec7962527c37671"

where Voting is my smart contract instance name

"0x6ee9957aef5f4073c6af71441ec7962527c37671" is deployed smart contact address

my web3.js version "web3": "^1.0.0-beta.31",

Sumption answered 28/9, 2018 at 11:30 Comment(3)
where we have to write 'Voting.options.address = "0x6ee9957aef5f4073c6af71441ec7962527c37671"' ?Hodgson
I have the same error that you got. Have you figure out where to add this code that @ngCourse recommend to add?Brenner
Please mention the file where we need to add the above code.Photophore
M
2
const accounts = await web3.eth.getAccounts()
this.setState({ 'account': accounts[0] });
const networkId = await web3.eth.net.getId()
const networkData = SocialNetwork.networks[networkId]
if (networkData) {
    const socialNetwork = web3.eth.Contract(SocialNetwork.abi, networkData.address)

} else {
    window.alert('oops')
}

This is the right way to set an address for your Contract. You can set the address by networkData.address

Mythos answered 27/2, 2020 at 20:37 Comment(0)
K
1

Thanks alot for this conversation, just started off with truffle in local environment and ran into this issue; It got solved , after this code in App.js `

const instance = new web3.eth.Contract(
        SimpleStorageContract.abi,
        deployedNetwork && deployedNetwork.address,
      );

` just addded this :

instance.options.address = " contract address on particular testnent ";

can be found in CONTRACT_NAME.js in networks where the network_id is 5777"

Krystenkrystin answered 3/4, 2022 at 18:56 Comment(0)
U
0

In my case, I realized that my directory was missing in my truffle-config.js file, which is why my networks field in migration.sol wasn't getting updated. I had to add the following line to fulfill the

contracts_build_directory: path.join(__dirname, "client/src/contracts"),

Undercast answered 21/2, 2022 at 17:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.