1 Star 0 Fork 0

binny1024 / truffle-prepare-for-lecture

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
  1. 类型还有 string, 定长浮点型 数组, 枚举
  2. 关于external, public, internal, private可以给一张这样的图https://www.itread01.com/content/1546054868.html

说明

ppt中的例子(1, 2, 3, ...)依次对应 contracts, migrations, test中的(2, 3, 4, ...)

contracts中的其他未标识数字的文件对应一本ERC20的依赖文件,其migration文件,对应其内序号10_deploy_mytoken.js, 其测试文件为test下的mytoken1.jsmytoken2.js.

truffle 文档

web3.js api reference

truffle compile

truffle migrate

truffle test .\test\mytoken1.js

The difference between mytoken1.js and mytoken2.js is almost nothing.

mytoken1.js is the official recommended style.

mytoken2.js is a better way to adjust if different test cases are independent.

In truffle console / truffle development mode

Get contract instance in truffle console:

  1. let instance = await MetaCoin.deployed()
  2. Or suppose contract address : 0x133739AB03b9be2b885cC11e3B9292FDFf45440E, we can use let instance = await MyToken.at("0x133739AB03b9be2b885cC11e3B9292FDFf45440E") to obtain the instance.

Call contract function (pre-invoke)

instance.name() / await instance.name()

isntance.symobl()

(await instance.totalSupply()).toNumber()

send Transaction: (invoke)

let result = await instance.transfer(accounts[1], 100)

the returned structure is the following:

result = {
    "tx": .., 
    "receipt": ..,
    "logs": []
}

await instance.approve(accounts[2], 100)

(await instance.allowance(accounts[0], accounts[2])).toNumber()

let result1 = await instance.transferFrom(accounts[0], accounts[2], 1, {from:accounts[2]}) ({from: ***} to indicate the msg.sender of this transaction)

about ether

Note: in truffle console, accounts by default means eth.web3.accounts

query balance : web3.eth.getBalance(accounts[0])

send ether: web3.eth.sendTransaction({from: accounts[0], to: accounts[1], value: web3.utils.toWei('1', "ether")})

From 7 on, we follow the test script styple giving OpenZeppelin.

npm install --save-dev @openzeppelin/test-helpers

For 14 npm install ethereumjs-abi --save

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/binny1024/truffle-prepare-for-lecture.git
git@gitee.com:binny1024/truffle-prepare-for-lecture.git
binny1024
truffle-prepare-for-lecture
truffle-prepare-for-lecture
master

搜索帮助