contract HamburgerCoin is StandardToken { string public name = "HamburgerCoin"; string public symbol = "HBC"; uint public decimals = 2; uint public INITIAL_SUPPLY = 10000 * (10 ** decimals);
function HamburgerCoin() public { totalSupply_ = INITIAL_SUPPLY; balances[msg.sender] = INITIAL_SUPPLY; } }
$ truffle compile Compiling ./contracts/HamburgerCoin.sol... Compiling zeppelin-solidity/contracts/math/SafeMath.sol... Compiling zeppelin-solidity/contracts/ownership/Ownable.sol... Compiling zeppelin-solidity/contracts/token/BasicToken.sol... Compiling zeppelin-solidity/contracts/token/ERC20.sol... Compiling zeppelin-solidity/contracts/token/ERC20Basic.sol... Compiling zeppelin-solidity/contracts/token/MintableToken.sol... Compiling zeppelin-solidity/contracts/token/StandardToken.sol... Writing artifacts to ./build/contracts Next you'll need to add a migration file which will tell truffle how to deploy your contract.
var mainNetPrivateKey = Buffer.from(process.env["MAINNET_PRIVATE_KEY"], "hex") var mainNetWallet = Wallet.fromPrivateKey(mainNetPrivateKey); var mainNetProvider = new WalletProvider(mainNetWallet, "https://mainnet.infura.io/");
var ropstenPrivateKey = Buffer.from(process.env["ROPSTEN_PRIVATE_KEY"], "hex") var ropstenWallet = Wallet.fromPrivateKey(ropstenPrivateKey); var ropstenProvider = new WalletProvider(ropstenWallet, "https://ropsten.infura.io/");
module.exports = { networks: { development: { host: "localhost", port: 8545, network_id: "*" // Match any network id }, ropsten: { provider: ropstenProvider, // You can get the current gasLimit by running // truffle deploy --network rinkeby // truffle(rinkeby)> web3.eth.getBlock("pending", (error, result) => // console.log(result.gasLimit)) gas: 4600000, gasPrice: web3.toWei("20", "gwei"), network_id: "3", }, mainnet: { provider: mainNetProvider, gas: 4600000, gasPrice: web3.toWei("20", "gwei"), network_id: "1", } } };
(LCTT 译注:原文采用 new Buffer 来获取私钥设置,但 node.js 升级后,废弃了 new Buffer 这种用法,运行时会发出警告,所以上面我修改为使用 Buffer.from 。)