Este problema se muestra con un mensaje.
Sé que hay un problema con la fuente. No hay una fuente alternativa pagable.
O
Esta fuente es de ethereum.org/token
function buy() payable returns (uint amount){
amount = msg.value / buyPrice; // calculates the amount
require(balanceOf[this] >= amount); // checks if it has enough to sell
balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
balanceOf[this] -= amount; // subtracts amount from seller's balance
Transfer(this, msg.sender, amount); // execute an event reflecting the change
return amount; // ends function and returns
}
function sell(uint amount) returns (uint revenue){
require(balanceOf[msg.sender] >= amount); // checks if the sender has enough to sell
balanceOf[this] += amount; // adds the amount to owner's balance
balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
revenue = amount * sellPrice;
msg.sender.transfer(revenue); // sends ether to the seller: it's important to do this last to prevent recursion attacks
Transfer(msg.sender, this, amount); // executes an event reflecting on the change
return revenue; // ends function and returns
}
Aquí abajo está mi fuente principal. Trabajé esto más de 40 horas sin dormir.
pragma solidity 0.4.19;
contract Token {
function totalSupply() constant returns (uint supply) {}
function balanceOf(address _owner) constant returns (uint balance) {}
function transfer(address _to, uint _value) returns (bool success) {}
function transferFrom(address _from, address _to, uint _value) returns (bool success) {}
function approve(address _spender, uint _value) returns (bool success) {}
function allowance(address _owner, address _spender) constant returns (uint remaining) {}
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
contract RegularToken is Token {
function transfer(address _to, uint _value) returns (bool) {
if (balances[msg.sender] >= _value && balances[_to] + _value >= balances[_to]) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
function transferFrom(address _from, address _to, uint _value) returns (bool) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value >= balances[_to]) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
function balanceOf(address _owner) constant returns (uint) {
return balances[_owner];
}
function approve(address _spender, uint _value) returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint) {
return allowed[_owner][_spender];
}
mapping (address => uint) balances;
mapping (address => mapping (address => uint)) allowed;
uint public totalSupply;
}
contract UnboundedRegularToken is RegularToken {
uint constant MAX_UINT = 2**256 - 1;
function transferFrom(address _from, address _to, uint _value)
public
returns (bool)
{
uint allowance = allowed[_from][msg.sender];
if (balances[_from] >= _value
&& allowance >= _value
&& balances[_to] + _value >= balances[_to]
) {
balances[_to] += _value;
balances[_from] -= _value;
if (allowance < MAX_UINT) {
allowed[_from][msg.sender] -= _value;
}
Transfer(_from, _to, _value);
return true;
} else {
return false;
}
}
}
contract ParentToken is UnboundedRegularToken {
uint public totalSupply = 20*10**26;
uint8 constant public decimals = 18;
string constant public name = "ParentToken";
string constant public symbol = "PAT";
function ParentToken() {
balances[msg.sender] = totalSupply;
Transfer(address(0), msg.sender, totalSupply);
}
}
Por favor, infórmeme sobre la fuente pagable y alternativa y dónde ubicarla.
El respaldo se activa cuando la firma de la función no coincide con ninguna de las funciones disponibles en un contrato de Solidity (como cuando envía ETH sin llamar específicamente a ninguna función).
Payable es un modificador que permite que un contrato acepte éteres. Puede hacer que una función sea pagadera y luego se pueden enviar éteres para contratar mientras llama a esta función. El wei
valor está presente en msg.value
el parámetro.
¿Dónde puedo poner mi fuente y qué elementos de la fuente deben cambiarse? ¿También la venta de funciones podría funcionar excepto por el signo de respaldo?
Ya que la has marcado buy
como función de pago. esto significa que puede llamar buy
pagando algo de ETH para contratar.
Pero si envía ETH directamente sin llamar a ninguna función. No servirá de mucho. Si desea que alguien pague ETH y buy
se invoque la función. Puede llamar a buy
la función desde la fallback
función. La función de reserva no tiene nombre de método.
function () payable{
buy();
}
Tenga cuidado con esto, ya que le permitirá contratar ETH y debe haber una fuente para retirar ETH del contrato.
aprender sobrehtml