I have a contract / dapp that is "pay to play". You send X amount of Eth, and you can play.
I have a price feed working via Chainlink, but I'd like to peg the Eth amount to USD.
Where the contract is now looking like..
uint public price = 0.15 ether;
I'd like to make that more dynamic.
uint public price = <$2.00 USD expressed as Eth>;
I'm not sure if this is even possible, because the price of Eth fluctuates so much. A tx could fire and while in the mempool, the price of Eth could jump and once the tx hits the function, it would be rejected.
function play() external payable returns(bool) {
require(
msg.value == price,
'Please send the correct amount of ETH'
);
So rather the price following the fluctuations of Eth so closely, perhaps it could change the price every hour or so?
Another idea I had was to make a function that changes the price, available only to the contracts author.
function changePrice(uint memory price) external ownerAddressOnly() {
this.price = price;
}
Where I could manually change the price when I choose, without having to redeploy a new contract.
How are operations like typically this handled in Solidity / Chainlink?