Search code examples
blockchainethereumsoliditybsc

In Solidity smart contracts, what variables can be made dynamic?


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?


Solution

  • 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