Blockchain 如何修改自定义功能的智能合约模板
我已经看了几个智能合约模板,并完成了几个教程。但是,他们没有一个人逐行检查这些代码的细节。我想添加一个函数,将公司利润的红利返还给客户,我应该在哪里添加它?例如,在下面的代码模板中,我可以在代码块中添加我的函数givebackdividence吗 有人能告诉我ICO智能合约的一般结构吗Blockchain 如何修改自定义功能的智能合约模板,blockchain,solidity,ico,smartcontracts,Blockchain,Solidity,Ico,Smartcontracts,我已经看了几个智能合约模板,并完成了几个教程。但是,他们没有一个人逐行检查这些代码的细节。我想添加一个函数,将公司利润的红利返还给客户,我应该在哪里添加它?例如,在下面的代码模板中,我可以在代码块中添加我的函数givebackdividence吗 有人能告诉我ICO智能合约的一般结构吗 contract HubiiCrowdsale is Crowdsale { uint private constant chunked_multiple = 18000 * (10 ** 18); // i
contract HubiiCrowdsale is Crowdsale {
uint private constant chunked_multiple = 18000 * (10 ** 18); // in wei
uint private constant limit_per_address = 100000 * (10 ** 18); // in wei
uint private constant hubii_minimum_funding = 17000 * (10 ** 18); // in wei
uint private constant token_initial_supply = 0;
uint8 private constant token_decimals = 15;
bool private constant token_mintable = true;
string private constant token_name = "Hubiits";
string private constant token_symbol = "HBT";
uint private constant token_in_wei = 10 ** 15;
// The fraction of 10,000 out of the total target tokens that is used to mint bonus tokens. These are allocated to the team's multisig wallet.
uint private constant bonus_base_points = 3000;
function HubiiCrowdsale(address _teamMultisig, uint _start, uint _end) Crowdsale(_teamMultisig, _start, _end, hubii_minimum_funding) public {
PricingStrategy p_strategy = new FlatPricing(token_in_wei);
CeilingStrategy c_strategy = new FixedCeiling(chunked_multiple, limit_per_address);
FinalizeAgent f_agent = new BonusFinalizeAgent(this, bonus_base_points, _teamMultisig);
setPricingStrategy(p_strategy);
setCeilingStrategy(c_strategy);
// Testing values
token = new CrowdsaleToken(token_name, token_symbol, token_initial_supply, token_decimals, _teamMultisig, token_mintable);
token.setMintAgent(address(this), true);
token.setMintAgent(address(f_agent), true);
token.setReleaseAgent(address(f_agent));
setFinalizeAgent(f_agent);
}
// These two setters are present only to correct block numbers if they are off from their target date by more than, say, a day
function setStartingBlock(uint startingBlock) public onlyOwner inState(State.PreFunding) {
require(startingBlock > block.number && startingBlock < endsAt);
startsAt = startingBlock;
}
function setEndingBlock(uint endingBlock) public onlyOwner notFinished {
require(endingBlock > block.number && endingBlock > startsAt);
endsAt = endingBlock;
}
}TL;博士这段代码只是使用块号定义ICO的开始和结束,但它扩展了各种其他源以实现令牌等。修改它不会导致任何问题
我想你是从错误的地方开始的。首先,您可以向任何契约添加任何代码,而不涉及其现有功能。我知道这有点为时过早,但我计划在第二天左右做两个关于ERC20和ERC223标准的教程,这是令牌应该围绕的设计。这将张贴在
ERC20
ERC223
contract ERC223 {
uint public totalSupply;
function balanceOf(address who) constant returns (uint);
function name() constant returns (string _name);
function symbol() constant returns (string _symbol);
function decimals() constant returns (uint8 _decimals);
function totalSupply() constant returns (uint256 _supply);
function transfer(address to, uint value) returns (bool ok);
function transfer(address to, uint value, bytes data) returns (bool ok);
function transfer(address to, uint value, bytes data, string custom_fallback) returns (bool ok);
event Transfer(address indexed from, address indexed to, uint value, bytes indexed data);
}
在您拥有代币合同后,您需要考虑ICO。使用ICO,您应该定义起点和终点。在上面的示例中,这是基于块的,这就是为什么您有:
require(startingBlock > block.number && startingBlock < endsAt);
这个合同是从一个名为Crowdsale的合同继承而来的,您的大部分实现看起来都来自于此。在这个令牌上可以找到完整的源代码,它基于ERC20标准,并且有相当多的继承树
令牌的代码在BasicToken中完成:
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint;
mapping(address => uint) balances;
/**
* Obsolete. Removed this check based on:
* https://blog.coinfabrik.com/smart-contract-short-address-attack-mitigation-failure/
* @dev Fix for the ERC20 short address attack.
*
* modifier onlyPayloadSize(uint size) {
* require(msg.data.length >= size + 4);
* _;
* }
*/
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint _value) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public constant returns (uint balance) {
return balances[_owner];
}
}
看起来它使用的是ERC20和ERC223标准,这很好,但是如果您试图遵循源代码,就会有点混乱
require(endingBlock > block.number && endingBlock > startsAt);
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint;
mapping(address => uint) balances;
/**
* Obsolete. Removed this check based on:
* https://blog.coinfabrik.com/smart-contract-short-address-attack-mitigation-failure/
* @dev Fix for the ERC20 short address attack.
*
* modifier onlyPayloadSize(uint size) {
* require(msg.data.length >= size + 4);
* _;
* }
*/
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint _value) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public constant returns (uint balance) {
return balances[_owner];
}
}