以太坊智能合约开发框架truffle学习
2018-02-01 10:57
555 查看
1. 安装
2. 建立MetaCoin工程
3. 启动私链(https://github.com/luoiefly/ethfun)
./geth --rpc --mine --minerthreads=1 --etherbase=aaba4749df21949095ff9445449ded85347f7154 console
4. 测试
cd MetaCoin
truffle compile
truffle migrate
报错: Error: No network specified. Cannot determine current network.
5. 要修改truffle.js配置
networks: {
development1 : {
host: "localhost",
port: 8545,
network_id: "*", // 匹配任何network id
gas: 3000000,
gasPrice: 0x1
}
}
6. truffle migrate
报错:Error: authentication needed: password or unlock
7. 要unlock account
WiRoams-MacBook-Air:bin luoie$ ./geth account list
Account #0: {15ed970cc673c6a8912c42663104c25e9d25698a} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-22T00-54-14.944479172Z--15ed970cc673c6a8912c42663104c25e9d25698a
Account #1: {aaba4749df21949095ff9445449ded85347f7154} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-22T00-54-24.027018315Z--aaba4749df21949095ff9445449ded85347f7154
Account #2: {b4e18cf5fa72cd47796b0bebc5bcc824d93c5c75} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-29T00-42-07.946381709Z--b4e18cf5fa72cd47796b0bebc5bcc824d93c5c75
Account #3: {e8c88c029ddd7b9880b9a3a8d1458ee7a1932dbb} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-29T14-26-23.123370914Z--e8c88c029ddd7b9880b9a3a8d1458ee7a1932dbb
WiRoams-MacBook-Air:bin luoie$
要使用第一个。
改变私链启动命令。
./geth --rpc --unlock 15ed970cc673c6a8912c42663104c25e9d25698a --mine --minerthreads=1 --etherbase=aaba4749df21949095ff9445449ded85347f7154 console
8. truffle migrate
报错:Error: unknown transaction
可能是版本问题。 Migration合约会出错, 但是直接用钱包部署合约会成功。
所以暂且不部署Migration。
cd migrations
vim 1_initial_migration.js
修改:
module.exports = function(deployer) {
//deployer.deploy(Migrations);
};
9. truffle migrate
WiRoams-MacBook-Air:MetaCoin luoie$ truffle migrate
Using network 'development'.
Running migration: 1_initial_migration.js
Saving artifacts...
Running migration: 2_deploy_contracts.js
Replacing ConvertLib...
... 0x1fd4a181f09d3df25c1c18109c9e305f5ee670e81f450872778219c03d1b7ec4
ConvertLib: 0xc7b9a4302748ba75da0c6a39a2c12ba2b1fb98bc
Linking ConvertLib to MetaCoin
Replacing MetaCoin...
... 0xcc67bd245f1260d27db72b250913c308e2c3245d0ff5c4aea4f90688232cf0dd
MetaCoin: 0x8ce003908df3075307c22a18d6a8951dccdb24e7
Saving artifacts...
WiRoams-MacBook-Air:MetaCoin luoie$
成功啦
10. 查看合约
cd build/contracts
vim MetaCoin.json
拷贝abi
打开以太坊钱包, 查找合约
npm install -g truffle
2. 建立MetaCoin工程
mkdir MetaCoin cd MetaCoin truffle unbox metacoin
3. 启动私链(https://github.com/luoiefly/ethfun)
./geth --rpc --mine --minerthreads=1 --etherbase=aaba4749df21949095ff9445449ded85347f7154 console
4. 测试
cd MetaCoin
truffle compile
truffle migrate
报错: Error: No network specified. Cannot determine current network.
5. 要修改truffle.js配置
networks: {
development1 : {
host: "localhost",
port: 8545,
network_id: "*", // 匹配任何network id
gas: 3000000,
gasPrice: 0x1
}
}
6. truffle migrate
报错:Error: authentication needed: password or unlock
7. 要unlock account
WiRoams-MacBook-Air:bin luoie$ ./geth account list
Account #0: {15ed970cc673c6a8912c42663104c25e9d25698a} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-22T00-54-14.944479172Z--15ed970cc673c6a8912c42663104c25e9d25698a
Account #1: {aaba4749df21949095ff9445449ded85347f7154} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-22T00-54-24.027018315Z--aaba4749df21949095ff9445449ded85347f7154
Account #2: {b4e18cf5fa72cd47796b0bebc5bcc824d93c5c75} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-29T00-42-07.946381709Z--b4e18cf5fa72cd47796b0bebc5bcc824d93c5c75
Account #3: {e8c88c029ddd7b9880b9a3a8d1458ee7a1932dbb} keystore:///Users/luoie/Library/Ethereum/keystore/UTC--2018-01-29T14-26-23.123370914Z--e8c88c029ddd7b9880b9a3a8d1458ee7a1932dbb
WiRoams-MacBook-Air:bin luoie$
要使用第一个。
改变私链启动命令。
./geth --rpc --unlock 15ed970cc673c6a8912c42663104c25e9d25698a --mine --minerthreads=1 --etherbase=aaba4749df21949095ff9445449ded85347f7154 console
8. truffle migrate
报错:Error: unknown transaction
可能是版本问题。 Migration合约会出错, 但是直接用钱包部署合约会成功。
所以暂且不部署Migration。
cd migrations
vim 1_initial_migration.js
修改:
module.exports = function(deployer) {
//deployer.deploy(Migrations);
};
9. truffle migrate
WiRoams-MacBook-Air:MetaCoin luoie$ truffle migrate
Using network 'development'.
Running migration: 1_initial_migration.js
Saving artifacts...
Running migration: 2_deploy_contracts.js
Replacing ConvertLib...
... 0x1fd4a181f09d3df25c1c18109c9e305f5ee670e81f450872778219c03d1b7ec4
ConvertLib: 0xc7b9a4302748ba75da0c6a39a2c12ba2b1fb98bc
Linking ConvertLib to MetaCoin
Replacing MetaCoin...
... 0xcc67bd245f1260d27db72b250913c308e2c3245d0ff5c4aea4f90688232cf0dd
MetaCoin: 0x8ce003908df3075307c22a18d6a8951dccdb24e7
Saving artifacts...
WiRoams-MacBook-Air:MetaCoin luoie$
成功啦
10. 查看合约
cd build/contracts
vim MetaCoin.json
拷贝abi
打开以太坊钱包, 查找合约
相关文章推荐
- 以太坊(Ethereum)开发框架 Truffle 入门(四):编译合约
- 区块链学习 以太坊truffle开发框架的安装使用
- Mac下基于testrpc和truffle的以太坊智能合约开发环境搭建
- 区块链学习(四)以太坊truffle开发框架的安装使用
- 以太坊学习之Java开发框架web3j的使用---部署合约
- 以太坊智能合约开发工具 Truffle 入门1
- 以太坊智能合约开发(truffle box pet-shop为例)
- 以太坊智能合约学习笔记(一)
- 『孔壹学院』以太坊(Ethereum)代币系统、智能合约开发实战课程
- 以太坊(Ethereum)开发框架 Truffle:引言
- 区块链开发(三)编写调试第一个以太坊智能合约
- 以太坊预言机与智能合约开发
- 以太坊系列之十六:golang进行智能合约开发
- 第一行代码:以太坊(2)-使用Solidity语言开发和测试智能合约
- 区块链开发(二)部署和运行第一个以太坊智能合约
- 以太坊 DApp 开发入门实战! 用Node.js和truffle框架搭建——区块链投票系统!
- Ethereum 智能合约 testrpc+truffle 开发环境搭建
- 区块链开发(八)以太坊truffle开发框架的安装使用
- 区块链开发(三)编写调试第一个以太坊智能合约