在weex 中的引入 Ethereum -web3.js
2019独角兽企业重金招聘Python工程师标准>>>
<script>
require("babel-core/register");
require("babel-polyfill");
import Web3 from 'web3'export default {name: "testWeb3",data() {return {web3: {},host: "http://127.0.0.1:7545", address: '0x50b04982c7a08De4Fe3e9F34dcEC1b06b835aE13',nonce: '',balanceWei:null};},methods: {createWeb3 () {let web3 = new Web3()let provider = new Web3.providers.HttpProvider(this.host)web3.setProvider(provider)return web3}},created() {this.web3 = this.createWeb3();// if (!this.web3.currentProvider.connected) {// throw new Error('请检查区块链的host或者interenet!')// }this.web3.eth.net.isListening((err, res) => {console.log(res) });//测试this.web3.eth.net.isListening().then((data) =>{if(data){console.log('isconnected:',data)}}).catch( (err) => {throw new Error('请检查区块链的host或者interenet!')});//获取当前 network IDthis.web3.eth.net.getId((err, res) => {console.log(res) //5777 });// 查看账号列表this.web3.eth.getAccounts( (err,res) => {console.log("查看账号列表:",res)})//查询矿工账号this.web3.eth.getCoinbase(function(error, result){ if (error) {console.error(error);} else {console.log("查询矿工账号:",result); }})// 获得余额 方法一this.web3.eth.getBalance(this.coinbase ,(err, res) => {if(!err) {let balance = this.web3.utils.fromWei(res, 'ether');console.log("this coinbase1: ",this.coinbase ) console.log("getBalance1:",balance) //100this.balanceWei = balance}else{console.log(err);}});// 获得余额 方法二let _self = this;async function getBalance (coinbase){try{let rs = await _self.web3.eth.getBalance(coinbase);return rs;} catch(err){console.error("error:",err);}}getBalance(this.coinbase).then(res => console.log('this.coinbase的余额:',res));//100000000000000000000;//新建账户let newAccount = this.web3.eth.accounts.create();console.log("新建账户:",newAccount)let info = this.web3.eth.accounts.encrypt(newAccount.privateKey, '12345678');console.log("新建账户的encrypt 信息:",info);//新建账户 personal.newAccount this.web3.eth.personal.newAccount('!@superpassword', (err, res) => {let newAddress = res; console.log('personal创建的新账户:',newAddress)//账户解锁this.web3.eth.personal.unlockAccount(newAddress, "!@superpassword",(err, res) => {console.log(newAddress+"解锁成功否:",res) //true}); });// 查看账号列表this.web3.eth.getAccounts( (err,res) => {console.log("查看账号列表:",res)});}
};
</script>
转载于:https://my.oschina.net/u/3734107/blog/1805190
在weex 中的引入 Ethereum -web3.js相关推荐
- 以太坊智能合约开发,Web3.js API 中文文档 ethereum web3.js入门说明
以太坊智能合约开发,Web3.js API 中文文档 ethereum web3.js入门说明 为了让你的Ðapp运行上以太坊,一种选择是使用web3.js library提供的web3.对象.底层实 ...
- React 组件js文件中如何引入其他的js 文件数组
在编写react 组件,特别是表格的过程中,我个人是最看不得,整个js文件感觉很多的内容,而且数组,函数,html代码都有,整体看起来分邋遢,我使用的是antd的Table 来渲染表格 我们看这样的一 ...
- html中如何引入vue,vue.js怎样引入到HTML中,vue引入第三方js库
vue.js怎样引入到HTML中如何将vue.js引入HTML,把vue.js引入HTML的方法:一.下载vue . js:然后在HTML中添加vue.js包,其语法为"script src ...
- 高德h5地图api接口_在uniapp h5中在线引入高德地图js api的方法分享
高德文档:https://lbs.amap.com/api/javascript-api/guide/abc/load 查询了好久都没有找到解决方法,弄好了分享一下. //这里要加window., l ...
- Web3.js API 中文文档
Web3.js API 中文文档 http://web3.tryblockchain.org/Web3.js-api-refrence.html web3对象提供了所有方法. 示例: //初始化过程 ...
- html 多个插件,webpack中html-webpack-plugin插件的使用(生成多个html页面,引入不同的js文件)...
以html-webpack-plugin插件为例 1.先安装插件,在命令行中输入:npm i -D html-webpack-plugin(执行完之后,在package.js的devDependen ...
- android web3j 代币查询_使用Web3.js查询以太币和代币余额以及转账
前言 前面的文章也提到了,使用web3.js可以与以太坊进行互动.这篇文章的主要内容如下:解决web3.js版本问题 2.使用web3.js查询以太币及代币余额,以及进行以太币和代币转账 1.web3 ...
- 4.1 web3.js概述
web3.js提供了用于和geth通信的JavaScript API.它内部使用JSON-RPC与geth通信.web3.js还可以与所有种类的.支持JSON-RPC的以太坊节点通信.它把所有JSON ...
- 区块链100讲:从宠物商店案例看DAPP架构和WEB3.JS交互接口
1 文章摘要 [本文目标] 了解ETH生态下DAPP去中心化应用程序的框架和交互流程,了解WEB3.JS的作用和接口函数. [前置条件] 完成了<技术小白如何开发一个DAPP区块链应用(以宠物商 ...
最新文章
- mysql设置约束l命令_mysql建表约束,sql
- error LNK2019: 无法解析的外部符号 __imp__accept@12
- mysql 数值类型 长度_mysql中的数据类型的长度
- ITK:用高斯核计算平滑
- node oauth2验证_如何设置和使用护照OAuth Facebook身份验证(第2部分)| Node.js
- Visual Studio 2008 安装失败(“Web 创作组件”无法安装)解决方法
- Bailian2815 城堡问题【DFS】
- SQL2K数据库开发七之表操作添加删除和修改列
- 很好的开源UI框架Chico UI
- Linux驱动的platform机制
- if……else if……else注意事项与基本用法
- [转] 大型ORACLE数据库优化设计方案
- 清理yarn、npm缓存包
- Go语言爱好者周刊:第 14 期
- 动手学深度学习实现DAY-2
- qq农场不换html5还用flash,QQ农场使用问题完整解答(6)
- 基站定位-基于基站的移动台定位
- Verilog语言快速入门
- COOX培训材料 — SCADA(4.Agitator)
- oracle服务丢失的解决办法
热门文章
- 脑机接口可以实时从脑电波中重建人脑中的图片?
- php输出json html,html怎样格式化输出JSON数据
- 奥密克戎新毒株XE出现!传播速度快10%
- 7小时44分最佳,睡多睡少都不好,养成习惯也没用
- 我从GitHub上看到了编程语言八年变迁史 | Reddit 30.7k
- 英特尔全新CPU和Xe独立显卡亮相,这次它把牙膏“挤爆了”
- 华为发布全世界最快AI产品,集成1024颗业内最强芯片,训练ResNet-50只需59.8秒
- 意念实时转语音!Facebook的非植入式脑机接口,解码准确率达到76%
- MIT“人造肌肉”登上Science封面,能提起自重650倍的物体,伸缩10000次都不坏
- Objective-C语言中对象相等性与指针相等分析。