0

This problem shows with a message

ERROR

I know there's problem with source There's no payable, fallback source in it.

  1. Please tell me about payable & fallback source and where to put it.

Or

This source is from 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
}
  1. where can i put in my source and which elements in the source has to be changed? Also function sell could work except for fallback sign?

Down here is my main source. I worked this over 40hours without sleeping

Please, I want to solve this struggles.

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);
    }
}

1 Answer 1

1

Please tell me about payable & fallback source and where to put it.

Fallback are triggered when the function signature does not match any of the available functions in a Solidity contract (like when you send ETH without specifically calling any function).

Payable is a modifier that allows a contract to accept ethers. You can make a function payable and then ethers can be sent to contract while calling this function. The wei value is present in msg.value param.

where can i put in my source and which elements in the source has to be changed? Also function sell could work except for fallback sign?

Since you have marked buy as payable function. this means you can call buy with paying some ETH to contract.

But if you send ETH directly without calling any function. It won't do much. If you want that someone pays ETH and buy function is invoked. You can call buy function from the fallback function. The fallback function has no method name.

function ()  payable{
    buy();
}

Be careful with this as this will allow you contract to accept ETH and there must be a source to withdraw ETH from the contract.

1
  • how can i use this function and where to put it? I would like to set up 1 eth = 10000 (symbol), 0.01 eth = 1000, 0.001 eth = 100 like this. however i have no idea please im beggin you.. help me out function () payable {buy (); } Commented May 6, 2018 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.