在文件夹下运行:
安装truffle
npm install -g truffle
mkdir tst 创建文件夹
cd tst/
truffle init 初始化环境
atom ./ 使用 atom打开
编写sol文件和migrations/文件夹下的js文件,写法就粘贴复制改下变量名和文件名就行
zhoukaideMacBook-Air:tst zhoukai$ truffle develop 启动环境
Truffle Develop started at http://127.0.0.1:9545/
…...
truffle(develop)> compile 编译
Compiling ./contracts/Migrations.sol...
Compiling ./contracts/helloworld.sol...
Writing artifacts to ./build/contracts
truffle(develop)> migrate —部署 重新部署 migrate --reset
Using network 'develop'.
Running migration: 1_initial_migration.js
Deploying Migrations...
... 0x6b42ac1887427e832e2188fe8dca7face2543e0038fdad3513497f627778ec78
Migrations: 0x8cdaf0cd259887258bc13a92c0a6da92698644c0
Saving successful migration to network...
... 0xd7bc86d31bee32fa3988f1c1eabce403a1b5d570340a3a9cdba53a472ee8c956
………..
Saving artifacts...
truffle(develop)> let contract 声明变量
undefined
truffle(develop)> helloworld.deployed().then(instance => contract = instance) 实例化
TruffleContract {
constructor:……..
truffle(develop)> contract.say() 调用方法 没有pure 调用为 contract.say.call(); 括号里可以写参数(根据实际方法来填写);
'helloworld'