[英]Interacting with a Smart Contract on private network through Web3.js
I have deployed my smart contract on private network using mist and geth. 我已经使用Mist和Geth将智能合约部署在专用网络上。
Now confusion is that : How can I interact with smart contract through Web3.js. 现在的困惑是:如何通过Web3.js与智能合约进行交互。
This is my script : 这是我的脚本:
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);
When I tried below commands: 当我尝试以下命令时:
> web3.providers
{
HttpProvider: function(host, timeout, user, password),
IpcProvider: function(path, net)
}
Once you set up infura you can use the portal url that they return to you to create your provider. 一旦设置了infura,就可以使用它们返回给您的门户网站URL来创建您的提供程序。 just edit your script to look like:
只需将脚本编辑为如下所示:
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(<your infura.io url here>));
}
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.