npm install -g truffle@3.2.1
npm install -g ethereumjs-testrpc
mkdir new_truffle
cd new_truffle
truffle init webpack
truffle.js新增如下代码(否则报错truffle No network specified. Cannot determine current network
):
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // 匹配任何network id
}
}
};
truffle compile
testrpc
truffle migrate
报错TypeError: fsevents is not a constructor
(修改truffle版本npm uninstall -g truffle npm install -g truffle@3.2.1
)
npm run dev
打开http://localhost:8080
打开后报错has not been deployed to detected network
(metamask必须设置为localhost:8545,To use Metamask with your local development blockchain, you need to point it at your testrpc.)
npm install -g truffle
npm install -g ganache-cli
修改truffle.js:
module.exports = {
networks: {
development: {
host: 'localhost',
port: '7545',
network_id: '*' // Match any network id
}
}
};
安装Ganache客户端并启动
truffle unbox metacoin
truffle compile
truffle migrate
truffle test
npm run dev
The name specified should match the name of the contract definition within that source file. Do not pass the name of the source file, as files can contain more than one contract.
Just like a promise, run an arbitrary deployment step.
deploy
and new
Moredeployed behaves like a singleton. It will look if there is already an instance of the contract deployed to the blockchain via deployer.deploy. The information about which contract has which address on which network is stored in the build folder. new will always create a new instance.
Don’t use Token.new
, but deployer.deploy
.
return deployer.deploy(Token, admin, totalTokenAmount).then(function(result) {
tokenContract = result;
return result;
}).then(function(result){
console.log("address", Token.address);
return result;
});