} catch (e) {
let v2 = await instance.methods.getValue().call()
“payable”: false,
03-instance
通过可视化界面可以直观地配置各类参数、欣赏查察账户和生意业务等数据
console.log(‘version:________’, web3.version)
//1.引入web3
操纵步调
“constant”: true,
“name”: “getValue”,
// console.log(‘interface____’,interface)
create-react-app project
//2.拼接bytecode
test() “type”: “constructor”
npm install -g cnpm –registry=https://registry.npm.taobao.org
let contractInstance = new web3.eth.Contract(abi, address)
•编写合约
所有的操纵都是在goland内里利用nodejs调web3库
//安装web3
from: from,
data: bytecode,//合约的bytecode
let fs = require(‘fs’)
“inputs”: [],
//此处abi已经json工具,,不需要举办parse行动
}).then(instance =>{
gasPrice:’1′,
})
//2.new一个web3实例
let web3 = new Web3()
开拓情况
let sourceCode = fs.readFileSync(‘./contracts/SimpleStorage.sol’, ‘utf-8’)04-interaction
git地点 https://github.com/potaxie/web3
//安装create-react-applet res = await instance.methods.setValue(‘Hello HangTou’).send({
from:account,
•找到合约实例
Ganache用于搭建私有网络。在开拓和测试情况下,Ganache提供了很是轻便的私有网络搭建要领,
01-compile
// console.log(‘bytecode_____’,bytecode)
“stateMutability”: “nonpayable”,
let output = solc.compile(sourceCode, 1)
“name”: “setValue”,
module.exports = contractInstance
“inputs”: [{“name”: “_str”, “type”: “string”}],
console.log(‘address__________’, contractInstance.options.address)
•web3-utils:开拓者东西相关
//3.配置网络
//此地点需要利用Ganache地点
let web3 = new Web3()
console.log(‘abi:______’,output[‘contracts’][‘:SimpleStorage’][‘interface’])
cnpm install [email protected]
•陈设合约(web3)
//2.读取数据
var solc = require(‘solc’)
//1.引入web3
let abi = [{
“outputs”: [],
•web3-bzz:与swarm存储协议相关
npm i web3 –save
npm run start
//1.导入合约实例
//安装淘宝的镜像
npm install create-react-app -g
“type”: “function”
gas:’3000000′,
let y1 = await instance.methods.getValue().call()
“stateMutability”: “view”,
//导出合约
}, {
console.log(‘address:’,instance.options.address)
//安装指定版本solc
a.陈设合约时候,需要用到提供abi,即可执行后头的行动,举办陈设 b.获取合约实例的时候需要用到这个函数,指定abi,指定address
let test = async () => {
“payable”: false,
//异法式用,返回值是一个promise
let instance = require(‘./03-instance’)
web3.setProvider(‘http://localhost:7545’)
}
})
//整体封装成函数
value: 0,
contract.deploy({
//导入solc编译器
}, {
挪用功效
}]“outputs”: [{“name”: “”, “type”: “string”}],
•web3-eth:与blockchain合约相关的模块
let Web3 = require(‘web3’)
//web3和交互的返回值都是promise,可以直接利用async
•挪用合约(set,get操纵)
//读取合约
•web3-shh:与p2p协议广播相关
console.log(e)
}).send({
console.log(‘output:’, output)
let contract = new web3.eth.Contract(JSON.parse(interface))
}
let {bytecode, interface} = require(‘./01-compile’)
arguments: [‘helloworld’]//给结构函数通报参数,利用数组
//1.拼接合约数据interface
“stateMutability”: “nonpayable”,
//获取合约实例,导出去
//进入到project中
代码加注解
const from = ‘0xd4DB91aCBB5Be2a42276567c7473857e14888B53’
“type”: “function”
//2.new一个web3实例
//建设空的react项目
const account =’0xd4DB91aCBB5Be2a42276567c7473857e14888B53′
“inputs”: [{“name”: “_str”, “type”: “string”}],
//3.配置网络
console.log(‘res:’, res)
•编译合约(web3)-用solc编译(拿到bytecode、abi)
let address = ‘0x7a0402FDB3de50eBEBe77F0ff72A6b7526e92447’ //此处是合约地点
web3.setProvider(‘http://localhost:7545’)
“constant”: false,
web3模块分别:
console.log(‘web3-eth.curretProvider_____________’, web3.currentProvider) console.log(‘v2:’, v2)
02-deploy
“payable”: false,
try {
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。