1

I understand that Smart Contracts are immutable once deployed. But how do you make changes to things like minting prices, gas prices afterward? Are there variables that can be written as dynamic for updates to be implemented through an admin panel?

  • 1
    gas prices can not be changed on a contract as they do not depend on the contract, gas prices are the price per unit of computational power and it will depends in multiple factors like network congestion, but long history short, if you want to change something later it needs to be a variable and have a setter function or you will need to use proxies – jhonny Dec 02 '21 at 02:52
  • To add to @jhonny comment First you need to understand that the gas price you pay are essentially tx fees which goes to miners minning the block. gas prices can be set by user for each transaction they are sending but if its too low than current avg gas price of network the miners will end up not adding your transaction to their block and it will stay in mempool (where are txs that are not yet added to any block live) too long and rejected eventually – hassan ahmed Dec 03 '21 at 10:32
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Dec 08 '21 at 13:18
  • @hassanahmed thanks bro. do you have a blockchain project that I can follow? – Shekhar Chopra Dec 09 '21 at 08:32

1 Answers1

2

In order to change variables you need to implement setter method.

uint256 public mintCost = 0.05 ether;

function setCost(uint256 _newCost) public onlyOwner {
        mintCost = _newCost;
 }

Above piece of code init a state variable that can be used as minting cost of a token and the function setCost is used to update its value. Also notice in onlyOwner that means function is restricted to be used by owner of the contract only. You can read more about function modifier from solidity docs

Gas prices are set while sending transactions incase you are using remix IDE it allows you to set gas price for each transaction.Value field is where you set gas price

hassan ahmed
  • 593
  • 3
  • 13