Can i disable direct transactions to smart contract address?

I wanna use rewardsAmount variable to calculate my rewards: uint rewardsAmount = 0; // Only here i can withdraw rewards function withdrawRewards() onlyOwner external { require(rewardsAmount != 0); owner.transfer(rewardsAmount); rewardsAmount = 0; } // If the contract doesn’t have users funds, then i can destroy it function kill() onlyOwner external { require(address(this).balance – rewardsAmount ==…

How to check if a mapping has not been written yet?

I have this mapping mapping (uint256 => string ) private storedData; I am trying to do this modifier dataNotStored(uint256 _index) { require( keccak256(abi.encodePacked(storedData[_index])) == keccak256(abi.encodePacked(”)) ); _; } function set(uint _index, string calldata _data_to_store) external dataNotStored(_index) { storedData[_index] = _data_to_store; } My goal is to avoid to allow only write for each entry of the…

How do miners communicate in Bitcoin/ Decentralized Network?

1.)If there is no central authority maintaining database how miners differentiate among other miners. 2.)Do they have there own database which have details(Mac/IP address) of neighbouring miners . 3.)Decentralized system feels absurd when i was trying to create blueprint where i was thinking to create a downloadable executable program ( socket programming for intercommunication) but…

Error: connection not open on send()

I’m using “web3“: “^1.2.4“ This is how I connect to ‘wss://kovan.infura.io/ws’ const web3 = new Web3(new Web3.providers.WebsocketProvider(‘wss://kovan.infura.io/ws’)) instance = new web3.eth.Contract(ABI, ADDRESS); Here I am trying to call PastEvents and for listening const eventOptions = { filter: {}, fromBlock: lastBlock, toBlock: ‘latest’ }; const events = await instance.getPastEvents(‘MyEvent’, eventOptions); instance.events.MyEvent(async function (error, result) { console.log(result)…