【发布时间】:2018-02-07 10:05:08
【问题描述】:
我已经使用mist 和geth 在私有网络上部署了我的智能合约。
现在的困惑是:如何通过 Web3.js 与智能合约交互。
这是我的脚本:
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
web3.eth.defaultAccount = web3.eth.accounts[0];
var CoursetroContract = web3.eth.contract(YOUR ABI);
var Coursetro = CoursetroContract.at('PASTE CONTRACT ADDRESS HERE');
console.log(Coursetro);
当我尝试以下命令时:
> web3.providers
{
HttpProvider: function(host, timeout, user, password),
IpcProvider: function(path, net)
}
【问题讨论】:
-
我使用infura。 infura.io。设置完成后,您可以使用 infura 链接而不是 localhost 链接。
标签: blockchain ethereum solidity smartcontracts web3js