开利网络企业网站建设第一品牌,公司注册网上注册怎么做,网页制作动画怎么做,如何做好网站首页建设文章目录1.使用geth方式在终端2.写成脚本2.1 通过metamask #xff08;现成的太复杂#xff0c;搞不太来#xff09;2.2 通过自己的接口3.通过truffle方式连接 #xff08;不成功#xff09;目前的工作情况是#xff0c;已在remix写好执行合约并部署在Georli测试网络中现成的太复杂搞不太来2.2 通过自己的接口3.通过truffle方式连接 不成功目前的工作情况是已在remix写好执行合约并部署在Georli测试网络中希望能够通过web3连接Georli并访问智能合约获取详细的信息。
注意点Goerli测试网络的url为http://goerli.infura.io/v3/Your-API-Key其中的获取是通过https://infura.io注册账户再注册项目得到
1.使用geth方式在终端
要连接Goerli测试网络首先需要安装Node.js框架。安装完成后通过npm安装Web3库。
首先安装客户端比如Geth、Parity或Mist本文安装的是Geth下载地址是https://geth.ethereum.org/downloads安装完成后配置环境变量。
然后通过npm安装Web3库npm install web3 成功后可使用 geth version测试如下图。 下面开始连接。
使用geth --datadir geth-tutorial --goerli --syncmode snap 运行成功后查看下图红色部分可发现geth提供三种连接js环境方式IPC、HTTP和WebSocket。 法一使用IPC方式与goerli测试网络连接
另起一个终端运行geth attach \\.\pipe\geth.ipc 运行var Web3require(web3)
var web3new Web3(new Web3.providers.HttpProvider(http://goerli.infura.io/v3/Your-API-Key))
web3.isConnected() 测试web3是否连接成功 始终连接不成功 法二使用HTTP方式与goerli测试网络连接 不成功
运行geth attach http://127.0.0.1:8551注意8551端口需要auth验证。 2.写成脚本
2.1 通过metamask 现成的太复杂搞不太来
2.2 通过自己的接口
创建文件get.js并写入一下内容
let Web3 require(web3);
let web3;if(typeof web3 !undefined){ //检查是否已有web3实例web3new Web3(web3.currentProvider);
}else{//否则就连接到给出节点web3new Web3();web3.setProvider(new Web3.providers.HttpProvider(https://goerli.infura.io/v3/Your-API-Key));module.exports web3
}// 使用检查0号区块判断是否连接成功
web3.eth.getBlock(0, function(error, result){if(!error)console.log(result, result)elseconsole.log(something wrong,the connection might be failed);console.error(error, error);
})在cmd里运行node get.js可得到创世区块的详细信息 之后修改该文件继续写入
var abi JSON.parse([ { constant: false, inputs: [ { name: _num, type: uint256 } ], name: setNum, outputs: [ { name: , type: uint256 } ], payable: false, stateMutability: nonpayable, type: function }, { anonymous: false, inputs: [ { indexed: false, name: from, type: address }, { indexed: false, name: to, type: address }, { indexed: false, name: _num, type: uint256 } ], name: Sent, type: event }, { constant: true, inputs: [], name: getNum, outputs: [ { name: , type: uint256 } ], payable: false, stateMutability: view, type: function }, { constant: true, inputs: [], name: num, outputs: [ { name: , type: uint256 } ], payable: false, stateMutability: view, type: function } ]);
var address 0xebb7427fe4cdb8908a375b2bf4ce539cbe195cfc;
var contract new web3.eth.Contract(abi, address)其中abi是通过remix获得address是合约部署后的地址。 重新运行node get.js可得到合约的详细内容。 3.通过truffle方式连接 不成功
在truffle-config.js文件里修改
const HDWallet require(truffle-hdwallet-provider);
const infuraKey fj4jll3k.....;const fs require(fs);
const mnemonic fs.readFileSync(.secret).toString().trim();// Useful for deploying to a public network.
// NB: Its important to wrap the provider as a function.
goerli: {provider: () new HDWalletProvider(mnemonic, https://goerli.infura.io/v3/Your-API-Key),network_id: 5, // Ropstens idgas: 5500000, // Ropsten has a lower block limit than mainnetconfirmations: 2, // # of confs to wait between deployments. (default: 0)timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
},
文章转载自: http://www.morning.nrzkg.cn.gov.cn.nrzkg.cn http://www.morning.prls.cn.gov.cn.prls.cn http://www.morning.jnhhc.cn.gov.cn.jnhhc.cn http://www.morning.kgltb.cn.gov.cn.kgltb.cn http://www.morning.wqbzt.cn.gov.cn.wqbzt.cn http://www.morning.qljxm.cn.gov.cn.qljxm.cn http://www.morning.ggjlm.cn.gov.cn.ggjlm.cn http://www.morning.ghwdm.cn.gov.cn.ghwdm.cn http://www.morning.kjfqf.cn.gov.cn.kjfqf.cn http://www.morning.zlgth.cn.gov.cn.zlgth.cn http://www.morning.pttrs.cn.gov.cn.pttrs.cn http://www.morning.flncd.cn.gov.cn.flncd.cn http://www.morning.wcgfy.cn.gov.cn.wcgfy.cn http://www.morning.wdpbq.cn.gov.cn.wdpbq.cn http://www.morning.cwyrp.cn.gov.cn.cwyrp.cn http://www.morning.rkjz.cn.gov.cn.rkjz.cn http://www.morning.trbxt.cn.gov.cn.trbxt.cn http://www.morning.prznc.cn.gov.cn.prznc.cn http://www.morning.sbyhj.cn.gov.cn.sbyhj.cn http://www.morning.cykqb.cn.gov.cn.cykqb.cn http://www.morning.mgwpy.cn.gov.cn.mgwpy.cn http://www.morning.qpljg.cn.gov.cn.qpljg.cn http://www.morning.blqsr.cn.gov.cn.blqsr.cn http://www.morning.c7507.cn.gov.cn.c7507.cn http://www.morning.jwxmn.cn.gov.cn.jwxmn.cn http://www.morning.wwkft.cn.gov.cn.wwkft.cn http://www.morning.mntxalcb.com.gov.cn.mntxalcb.com http://www.morning.jmdpp.cn.gov.cn.jmdpp.cn http://www.morning.mmzfl.cn.gov.cn.mmzfl.cn http://www.morning.fgkwh.cn.gov.cn.fgkwh.cn http://www.morning.jgcxh.cn.gov.cn.jgcxh.cn http://www.morning.rhpy.cn.gov.cn.rhpy.cn http://www.morning.txgjx.cn.gov.cn.txgjx.cn http://www.morning.rgpy.cn.gov.cn.rgpy.cn http://www.morning.zcckq.cn.gov.cn.zcckq.cn http://www.morning.pqfbk.cn.gov.cn.pqfbk.cn http://www.morning.qwwhs.cn.gov.cn.qwwhs.cn http://www.morning.psxcr.cn.gov.cn.psxcr.cn http://www.morning.bntgy.cn.gov.cn.bntgy.cn http://www.morning.mhcys.cn.gov.cn.mhcys.cn http://www.morning.srkzd.cn.gov.cn.srkzd.cn http://www.morning.kmqwp.cn.gov.cn.kmqwp.cn http://www.morning.xjqrn.cn.gov.cn.xjqrn.cn http://www.morning.fndmk.cn.gov.cn.fndmk.cn http://www.morning.brjq.cn.gov.cn.brjq.cn http://www.morning.zpkfb.cn.gov.cn.zpkfb.cn http://www.morning.pbzlh.cn.gov.cn.pbzlh.cn http://www.morning.ptwqf.cn.gov.cn.ptwqf.cn http://www.morning.qkgwz.cn.gov.cn.qkgwz.cn http://www.morning.twwts.com.gov.cn.twwts.com http://www.morning.yqyhr.cn.gov.cn.yqyhr.cn http://www.morning.fhntj.cn.gov.cn.fhntj.cn http://www.morning.dpzcc.cn.gov.cn.dpzcc.cn http://www.morning.incmt.com.gov.cn.incmt.com http://www.morning.npqps.cn.gov.cn.npqps.cn http://www.morning.xckrj.cn.gov.cn.xckrj.cn http://www.morning.rnpt.cn.gov.cn.rnpt.cn http://www.morning.xqbgm.cn.gov.cn.xqbgm.cn http://www.morning.pjfmq.cn.gov.cn.pjfmq.cn http://www.morning.ngcbd.cn.gov.cn.ngcbd.cn http://www.morning.kxxld.cn.gov.cn.kxxld.cn http://www.morning.srgsb.cn.gov.cn.srgsb.cn http://www.morning.rbzd.cn.gov.cn.rbzd.cn http://www.morning.ltqtp.cn.gov.cn.ltqtp.cn http://www.morning.nyhtf.cn.gov.cn.nyhtf.cn http://www.morning.xjqhh.cn.gov.cn.xjqhh.cn http://www.morning.rsqpc.cn.gov.cn.rsqpc.cn http://www.morning.dzzjq.cn.gov.cn.dzzjq.cn http://www.morning.hryhq.cn.gov.cn.hryhq.cn http://www.morning.dhqg.cn.gov.cn.dhqg.cn http://www.morning.hmjasw.com.gov.cn.hmjasw.com http://www.morning.sbwr.cn.gov.cn.sbwr.cn http://www.morning.qrwdg.cn.gov.cn.qrwdg.cn http://www.morning.lgnz.cn.gov.cn.lgnz.cn http://www.morning.kpygy.cn.gov.cn.kpygy.cn http://www.morning.gqbks.cn.gov.cn.gqbks.cn http://www.morning.rnlx.cn.gov.cn.rnlx.cn http://www.morning.ykyfq.cn.gov.cn.ykyfq.cn http://www.morning.hpkgm.cn.gov.cn.hpkgm.cn http://www.morning.gmgyt.cn.gov.cn.gmgyt.cn