未处理的拒绝错误:此合同对象尚未设置地址,请先设置地址

时间:2018-02-04 15:47:41

标签: ethereum web3js

我目前正在尝试使用Infura通过Web3在我的机器上运行。当我设置运行我的node index.js文件时,我收到以下错误:

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

我想也许问题是在Infura端口443上运行。

2 个答案:

答案 0 :(得分:3)

  

简单的解决方案

Voting.options.address = "0x6ee9957aef5f4073c6af71441ec7962527c37671"

其中投票是我的智能合约实例名称

0x6ee9957aef5f4073c6af71441ec7962527c37671 ”是 已部署的智能联系人地址

我的web3.js版本  “ web3”:“ ^ 1.0.0-beta.31”,

答案 1 :(得分:0)

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')
}

这是为合同设置地址的正确方法。您可以通过 networkData.address

设置地址