使用 truffle 环境测试 solidity 智能合约

在文件夹下运行:

安装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'

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值