介绍
怎么在weex中的引入Ethereum web3。js,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
& lt; script> 要求(“babel-core/register"); 要求(“babel-polyfill"); import Web3 得到& # 39;web3 # 39; export default  { ,,名字:“testWeb3", 数据才能(),{ ,,,return { ,,,,,,web3:, {}, ,,,,,,主持人:,“http://127.0.0.1:7545",,, ,,,,,,地址:,& # 39;0 x50b04982c7a08de4fe3e9f34dcec1b06b835ae13& # 39; ,,,,,,现时标志:,& # 39;& # 39; ,,,,,,balanceWei:零 ,,,}; ,,}, 方法:才能,{ ,,,,createWeb3 (), { ,,,,,,,let web3 =, new Web3 () ,,,,,,,let provider =, new Web3.providers.HttpProvider (this.host) ,,,,,,,web3.setProvider(供应商) ,,,,,,,return web3 ,,,} ,,}, ()创建的才能,{ ,,,,,this.web3 =, this.createWeb3 (); ,,,,,//,if (! this.web3.currentProvider.connected), { ,,,,,//,,,throw new 错误(& # 39;请检查区块链的主机或者interenet ! & # 39;) ,,,,,//,} ,,,,,this.web3.eth.net.isListening((呃,,res),=祝辞,{ ,,,,,,,,,console.log (res),,,,,, ,,,,,}); ,,,,//测试 ,,,,,this.web3.eth.net.isListening(),然后((数据),=在{ ,,,,,,,,,如果(数据){ ,,,,,,,,,,,console.log(& # 39;与:& # 39;,数据) ,,,,,,,,,, ,,,,,,,,,} ,,,,,,}).catch (, (err)=祝辞,{ ,,,,,,,,,,throw new 错误(& # 39;请检查区块链的主机或者interenet ! & # 39;) ,,,,,,}); ,,,,, ,,,,,//获取当前,network ID ,,,,,this.web3.eth.net.getId((呃,,res),=祝辞,{ ,,,,,,,,,console.log (res),,//5777,,,,,,,, ,,,,,}); ,,,,,//,查看账号列表 ,,,,,this.web3.eth.getAccounts(,(呃,res)=祝辞,{ ,,,,,,console.log(“查看账号列表:“(res) ,,,,,}) ,,,,,//查询矿工账号 ,,,,,this.web3.eth.getCoinbase ( ,,,,,,,,,(错误,,结果){函数, ,,,,,,,,,if (错误),{ ,,,,,,,,,,,,,console.error(错误); ,,,,,,,,,},{else ,,,,,,,,,,,,,console.log(“查询矿工账号:“,结果),, ,,,,,,,,,} ,,,,,}) ,,,,, ,,,,,//,获得余额,方法一 ,,,,,this.web3.eth.getBalance (this.coinbase ,(呃,,res),=祝辞,{ ,,,,,,,,, ,,,,,,,,,如果(!呃),,{ ,,,,,,,,,,,let balance =, this.web3.utils.fromWei (res, & # 39;醚# 39;); ,,,,,,,,,,,console.log(“却;能够coinbase1:,“, this.coinbase ),, ,,,,,,,,,,,console.log (“getBalance1:“平衡),,,//100 ,,,,,,,,,,,this.balanceWei =,平衡 ,,,,,,,,,其他}{ ,,,,,,,,,,,,console.log(错); null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null怎么在weex中的引入Ethereum -web3.js