Shekhar Chopra
Shekhar Chopra

Reputation: 13

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?

Upvotes: 1

Views: 1011

Answers (1)

hassan ahmed
hassan ahmed

Reputation: 614

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

Upvotes: 2

Related Questions