truffle常命令
truffle compile
truffle migrate
truffle console
truffle test
abi:整個contract中函数的结构,告诉外部语言,该合约在evm中的结构,外部语言可以根据abi生成javascript或者go生产合约实例。
介绍:migrations
顺序执行migrations
deploy 分阶梯或者stage来进行部署
在合约文件目录中,使用truffle.console
WEB3.js是一个 web和区块链的一个交互桥梁,他读取
web3.tab
web3.currentProvider (当前ether网络信息)
web3调用合约方程
方程名.call()
方程名.send() or 方程名()
call() 只会在本地node中执行,读取区块链信息. 方程名() , 会与整个区块链网络节点进行通信。
前端开发:
truffle box , 前端开发应用脚手架 web3 (JavaScript lib)
truffle unbox react
合约测试可以利用js和solidity
利用solidity进行测试,合约名字和方法名均需更改为test
solidity用单元测试,可对interal函数进行测试.
js里面可以整合测试,不可对interal函数进行测试.
问题:js 和solidity测试有什么区别?
https://solidity.readthedocs.io/en/develop/contracts.html#inheritance
npm install
https://truffleframework.com/boxes/react
https://gitee.com/shuzheng/zheng
ganache-cli -a 20 -e 10000 -l 9000000
truffle compile
truffle migrate --reset
npm run start
忽略错误,打开 http://localhost:3000/ 应该可看到界面
##### ganache-cli
https://my.oschina.net/u/3790537/blog/1802985
ganache-cli -a 20 -e 1000 -l 9000000
(0) 0xccedfa875e1d47dc445dc8e13f9aa9573f5dfac5
(1) 0x01f5e9c132d5d6486dffbcf8e6441553d695bb6a
(2) 0x0119dc88fbfa6852093cfdaf7dd88789dbca7b7b
(3) 0xfc8b0755e4331d472b0247395b998e125ebf5334
(4) 0x834a161c68335fbfda33e09a8cbf89fd22a699cd
(5) 0x187c71eb05c049a53d8a829c0831c67dd81bf82b
(6) 0xc7dabc2f237e37847f28f8d5b2dd7c76527fd2e5
(7) 0xc54a9fcc515a7d14c42a92099697684b2aad6212
(8) 0xe3116bba7f13379b4e44fa3357a8575f48f6bc25
(9) 0xd3f42aa97063f10ea686bcb44459c0ebd6d88a92
(10) 0x6c54790b07442b0bc8f441eaee66534d3c20ff5e
(11) 0x647dc1047b5332a4000d6283ec1e311842ebe17e
(12) 0xfa61fd255d7ad34a63ce8d058a4148b0045226ac
(13) 0x69f18056fd41262a699d4e87319ee58a3574548c
(14) 0x72d17820c536f7b0234490cc5266afcd1328a741
(15) 0x7b041d0ad5febc79373db1aff165a1886fa75dd7
(16) 0xc2e1a6368f91136fc889f6a92f1506dba5c15042
(17) 0x4a753c9b9f849b73b8daa463c12b21df9f162756
(18) 0x9671702063e445125df0082d6bbb5cb1fd813d9a
(19) 0x698e29eff3c9641900f6f845447bf9724f3bedac
测试步骤
ganache-cli -a 20 -e 10000
truffle compile
truffle migrate --reset
npm run start
/**忽略错误,打开 http://localhost:3000/ 应该可看到界面**/
truffle(development)> Payroll.deployed().then(instance => payroll=instance)
web3.eth.accounts
payroll.addEmployee('0xceeb48dca2db5d15fa362a647214811a1fd8da32',2)
payroll.employees.call('0xceeb48dca2db5d15fa362a647214811a1fd8da32').then(result => console.log(result))
网友评论