truffle 是世界级的以太坊开发框架
•内置智能合约编译、连接、开发和二进制管理•快速开发的自动化合约测试•脚本、可扩展性部署和迁移框架•用于部署到任意数量的公网和私网的网络管理•为合约通信提供交互式控制台
truffle init
•contracts: 存放合约•migrations:存放部署脚本•test:测试文件•truffle-config.js: 配置文件,配置不同网络
pragma solidity ^0.4.24;
contract SimpleStorage{
uint storedData;
function set(uint x) public{
storedData =x;
}
function get() public view returns (uint){
return storedData;
}
}
truffle compile
执行编译之后,会生成build文件夹,里面会有abi、bytecode、network
const SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
deployer.deploy(SimpleStorage);
};
//你所要部署的网络的名字
ganacheNet: {
host: "127.0.0.1", // Localhost (default: none)
port: 7545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
},
truffle migrate --network ganacheNet
此时交易已经产生到ganache
at address 用 ganache 里面的 create address
Git 地址 https://github.com/potaxie/truffle-init
本文作者:potaxie
作者主页:
https://learnblockchain.cn/people/633