Unhandled rejection Error: This contract object doesn't have address set yet, please set an address first
Unhandled rejection Error: This contract object doesn't have address set yet, please set an address first
我目前正在尝试通过 Web3 在我的机器上使用 Infura 运行。当我设置为 运行 我的 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 上。
Simple solution
Voting.options.address = "0x6ee9957aef5f4073c6af71441ec7962527c37671"
其中 投票 是我的 智能合约实例 名称
"0x6ee9957aef5f4073c6af71441ec7962527c37671"是部署的智能联系人地址
我的web3.js版本
"web3": "^1.0.0-beta.31",
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
设置地址
在我的例子中,我意识到我的目录在我的 truffle-config.js 文件中丢失了,这就是我在 migration.sol 中的网络字段没有得到更新的原因。我必须添加以下行来完成
contracts_build_directory: path.join(__dirname, "client/src/contracts"),
非常感谢这次谈话,刚从本地环境中的 truffle 开始,运行 进入这个问题;
它得到解决,
在 App.js 中的这段代码之后
`
const instance = new web3.eth.Contract(
SimpleStorageContract.abi,
deployedNetwork && deployedNetwork.address,
);
`
刚刚添加了这个:
instance.options.address = " contract address on particular testnent ";
可以在 CONTRACT_NAME.js 网络中找到 network_id 是 5777
我目前正在尝试通过 Web3 在我的机器上使用 Infura 运行。当我设置为 运行 我的 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 上。
Simple solution
Voting.options.address = "0x6ee9957aef5f4073c6af71441ec7962527c37671"
其中 投票 是我的 智能合约实例 名称
"0x6ee9957aef5f4073c6af71441ec7962527c37671"是部署的智能联系人地址
我的web3.js版本 "web3": "^1.0.0-beta.31",
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
设置地址在我的例子中,我意识到我的目录在我的 truffle-config.js 文件中丢失了,这就是我在 migration.sol 中的网络字段没有得到更新的原因。我必须添加以下行来完成
contracts_build_directory: path.join(__dirname, "client/src/contracts"),
非常感谢这次谈话,刚从本地环境中的 truffle 开始,运行 进入这个问题; 它得到解决, 在 App.js 中的这段代码之后 `
const instance = new web3.eth.Contract(
SimpleStorageContract.abi,
deployedNetwork && deployedNetwork.address,
);
` 刚刚添加了这个:
instance.options.address = " contract address on particular testnent ";
可以在 CONTRACT_NAME.js 网络中找到 network_id 是 5777