跟乐乐学web3开发一.使用IDE工具webstorm来编写web3js
Posted 君を見つけて
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了跟乐乐学web3开发一.使用IDE工具webstorm来编写web3js相关的知识,希望对你有一定的参考价值。
前言
web3可以用java语言来编写,通过java的web3j依赖来编写,但是web3j对于abi的应用等支持库不太完整,所以还是多少有点局限性。
因此在当今的web3领域中,使用基于javascript的web3.js库来编写web3应用是主流。
市面上大多的教材中,对于web3.js的编写是基于vscode这一款ide工具,这里我则是使用了webStorm来编写。
在使用webstorm编写web3应用前,需要确保你的环境已经安装了nodeJs以及npm。
同时,读者需要具有一定的javaScript基础,这样才能较好的利用api文档进行学习。
我的nodejs版本:v9.4.0
npm版本:5.6.0
一.web3的Api了解
在具有js基础上,我们通过web3的api文档,能够最快的实现和contract进行交互以及block扫描等操作。
api文档建议参考这两个:
https://web3js.readthedocs.io/en/v1.7.3/web3-eth-contract.html
https://www.qikegu.com/docs/5132
二.abi是什么?(重要)
根据一些类似官方的说法,abi是如下解释:
ABI代表“Abstract Binary Interface/抽象二进制接口”,它是一个JSON数组,是面向以太坊虚拟机的可执行文件,类似于windows 平台上的二进制可执行文件。智能合约编译后生成ABI文件,可以在以太坊虚拟机上执行。
是不是不好理解?
那么通俗来说,abi会用json形式,定义了你和contract交互时,能够调用哪些函数或者查看哪些变量。
比如,bsc中的绝大部分contract,都有一个叫做’decimals()'的函数,如果我想调用它,我就需要先在abi中以json形式声明这个函数的存在,之后进行调用。
这就类似于你在java中反射了一个类,想要调用它的方法,就需要准确的输入它的方法名一样。
三.建立web3项目
自定义你的项目路径
创建成功
安装web3js依赖
输入命令:
npm install web3
执行后,如果没有error则说明安装成功
四.编写一个简单的web3脚本
接下来,我们来编写一个简单的脚本,根据contract地址来获取它的符号。
新建一个叫demo的目录
新建一个demo脚本
脚本内容如下:
const Web3 = require('web3'); // 加载web3库
const web3Bsc = new Web3("https://bsc-dataseed1.binance.org:443"); // 通过web3库,连接bsc链上节点,从而实例化bsc链上web3节点对象。
// 定义abi,abi能够以json形式,规定能够和该contract的哪些函数或者变量进行交互,比如调用它get/set函数。
const abi = ["inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor","anonymous":false,"inputs":["indexed":true,"internalType":"address","name":"owner","type":"address","indexed":true,"internalType":"address","name":"spender","type":"address","indexed":false,"internalType":"uint256","name":"value","type":"uint256"],"name":"Approval","type":"event","anonymous":false,"inputs":["indexed":true,"internalType":"address","name":"previousOwner","type":"address","indexed":true,"internalType":"address","name":"newOwner","type":"address"],"name":"OwnershipTransferred","type":"event","anonymous":false,"inputs":["indexed":true,"internalType":"address","name":"from","type":"address","indexed":true,"internalType":"address","name":"to","type":"address","indexed":false,"internalType":"uint256","name":"value","type":"uint256"],"name":"Transfer","type":"event","constant":true,"inputs":[],"name":"_decimals","outputs":["internalType":"uint8","name":"","type":"uint8"],"payable":false,"stateMutability":"view","type":"function","constant":true,"inputs":[],"name":"_name","outputs":["internalType":"string","name":"","type":"string"],"payable":false,"stateMutability":"view","type":"function","constant":true,"inputs":[],"name":"_symbol","outputs":["internalType":"string","name":"","type":"string"],"payable":false,"stateMutability":"view","type":"function","constant":true,"inputs":["internalType":"address","name":"owner","type":"address","internalType":"address","name":"spender","type":"address"],"name":"allowance","outputs":["internalType":"uint256","name":"","type":"uint256"],"payable":false,"stateMutability":"view","type":"function","constant":false,"inputs":["internalType":"address","name":"spender","type":"address","internalType":"uint256","name":"amount","type":"uint256"],"name":"approve","outputs":["internalType":"bool","name":"","type":"bool"],"payable":false,"stateMutability":"nonpayable","type":"function","constant":true,"inputs":["internalType":"address","name":"account","type":"address"],"name":"balanceOf","outputs":["internalType":"uint256","name":"","type":"uint256"],"payable":false,"stateMutability":"view","type":"function","constant":false,"inputs":["internalType":"uint256","name":"amount","type":"uint256"],"name":"burn","outputs":["internalType":"bool","name":"","type":"bool"],"payable":false,"stateMutability":"nonpayable","type":"function","constant":true,"inputs":[],"name":"decimals","outputs":["internalType":"uint8","name":"","type":"uint8"],"payable":false,"stateMutability":"view","type":"function","constant":false,"inputs":["internalType":"address","name":"spender","type":"address","internalType":"uint256","name":"subtractedValue","type":"uint256"],"name":"decreaseAllowance","outputs":["internalType":"bool","name":"","type":"bool"],"payable":false,"stateMutability":"nonpayable","type":"function","constant":true,"inputs":[],"name":"getOwner","outputs":["internalType":"address","name":"","type":"address"],"payable":false,"stateMutability":"view","type":"function","constant":false,"inputs":["internalType":"address","name":"spender","type":"address","internalType":"uint256","name":"addedValue","type":"uint256"],"name":"increaseAllowance","outputs":["internalType":"bool","name":"","type":"bool"],"payable":false,"stateMutability":"nonpayable","type":"function","constant":false,"inputs":["internalType":"uint256","name":"amount","type":"uint256"],"name":"mint","outputs":["internalType":"bool","name":"","type":"bool"],"payable":false,"stateMutability":"nonpayable","type":"function","constant":true,"inputs":[],"name":"name","outputs":["internalType":"string","name":"","type":"string"],"payable":false,"stateMutability":"view","type":"function","constant":true,"inputs":[],"name":"owner","outputs":["internalType":"address","name":"","type":"address"],"payable":false,"stateMutability":"view","type":"function","constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","constant":true,"inputs":[],"name":"symbol","outputs":["internalType":"string","name":"","type":"string"],"payable":false,"stateMutability":"view","type":"function","constant":true,"inputs":[],"name":"totalSupply","outputs":["internalType":"uint256","name":"","type":"uint256"],"payable":false,"stateMutability":"view","type":"function","constant":false,"inputs":["internalType":"address","name":"recipient","type":"address","internalType":"uint256","name":"amount","type":"uint256"],"name":"transfer","outputs":["internalType":"bool","name":"","type":"bool"],"payable":false,"stateMutability":"nonpayable","type":"function","constant":false,"inputs":["internalType":"address","name":"sender","type":"address","internalType":"address","name":"recipient","type":"address","internalType":"uint256","name":"amount","type":"uint256"],"name":"transferFrom","outputs":["internalType":"bool","name":"","type":"bool"],"payable":false,"stateMutability":"nonpayable","type":"function","constant":false,"inputs":["internalType":"address","name":"newOwner","type":"address"],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"];
// 获取token符号(名称)
async function getTokenSymbol()
const contractAddress = new web3Bsc.eth.Contract(abi,"0x1d2f0da169ceb9fc7b3144628db156f3f6c60dbe"微信小程序IDE(微信web开发者工具)安装破解手册--转载
1、IDE下载
微信web开发者工具,本人是用的windows 10 x64系统,用到以下两个版本的IDE安装工具与一个破解工具包:
wechat_web_devtools_0.7.0_x64.exe下载地址:点我下载
wechat_web_devtools_0.9.092100_x64.exe下载地址:
- 百度: https://pan.baidu.com/s/1pLTKIqJ (密码: iswg)
- 360: https://yunpan.cn/ckvXjEbnFYMSC (提取码:f9ca)
破解包下载地址(相关文件已按照目录位置存储):http://files.cnblogs.com/files/zsy/%E5%BE%AE%E4%BF%A1web%E5%BC%80%E5%8F%91%E8%80%85ide%E7%A0%B4%E8%A7%A3.zip
2、安装步骤
请严格按照以下步骤进行安装。
2.1 安装wechat_web_devtools_0.7.0_x64
记下安装目录:E:\\Program Files\\Tencent\\微信web开发者工具
2.2 运行wechat_web_devtools_0.7.0_x64
选择“运行 微信web开发者工具 0.7.0”,点击“完成”按钮,弹出以下界面:
请用手机微信进行扫描:
在手机上,点击“确认登录”按钮:
登录之后窗口进入如下界面:
登录成功之后, 退出程序。
2.3 安装wechat_web_devtools_0.9.092100_x64
wechat_web_devtools_0.9.092100_x64进行覆盖安装,也安装到E:\\Program Files\\Tencent\\微信web开发者工具 目录下。
安装之后暂时不要运行程序,要对安装程序进行破解。
2.4 微信web开发者工具破解
打开目录E:\\Program Files\\Tencent\\微信web开发者工具\\package.nw ,下载破解文件,覆盖app目录即可。
- \\package.nw\\app\\dist\\components\\create\\createstep.js
- \\package.nw\\app\\dist\\stroes\\projectStores.js
- \\package.nw\\app\\dist\\weapp\\appservice\\asdebug.js
替换这三个文件,即可完成破解。
3、开始使用
1、首先在e盘下创建一个wxapp目录
2、打开桌面“微信web开发者工具”
点击“添加项目”,进入“新建项目”界面:
- AppID:随便填
- 项目名称:随便填
- 本地开发目录:选择一个目录,比如刚才创建目录E:\\wxapp
设置完成,点击“添加项目”按钮,进入如下界面
按照这个方法完全破解了,但是有个问题是,他会自动更新,第二次就打不开了
以上是关于跟乐乐学web3开发一.使用IDE工具webstorm来编写web3js的主要内容,如果未能解决你的问题,请参考以下文章
为啥这个智能合约功能在使用 web3 提供程序的 Remix IDE 上不起作用?