簡體   English   中英

通過Web3.js與專用網絡上的智能合約進行交互

[英]Interacting with a Smart Contract on private network through Web3.js

我已經使用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,就可以使用它們返回給您的門戶網站URL來創建您的提供程序。 只需將腳本編輯為如下所示:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM