I need to create an erc20 token with the function "payable" thats means that when you send some ether to the token contract (like 1 Token = 0.5 ETH) send the amount of tokens to the wallet that sent the ether, see an example here:


But I need the permition to change the price whenever I want, and change the supply (burn and add tokens) too.

some examples?


It would be helpful to see your contract code to better help you, but in general what you can do is create a state variable that represents the price of your token in wei and then create a setter function that changes that value.

uint public price;

function setPrice(uint newPrice) public {
    require(newPrice > 0);
    price = newPrice;

The same can be said for adding and subtracting your total supply of tokens.

uint public totalSupply = 100000;

function addTokenToTotalSupply(uint _value) public {
    require(_value > 0);
    balances[msg.sender] = balances[msg.sender] + _value;
    totalSupply = totalSupply + _value;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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