Are contracts really that different? I guess in theory every contract should have a private key somewhere + it should be possible to send ether to it? Unless geth/parity and other parts of the evm don't have functions specifically checking if every blockchain transfer is wallet vs contract and hence rejecting ether if it's send to contract without payable functions?
So can I simply send ether to a contract as if it's a regular wallet, even without payable function?
1 Answer
every contract should have a private key somewhere
The private key exists in theory, but since the contract address is not generated by choosing a private key to begin with, the private key of that address remains unknown (and unlikely to be discovered under the current computation limits).
it should be possible to send ether to it
Only if it implements a payable
function (this restriction was added at an early stage of the Ethereum blockchain, in order to reduce the amount of unintentional transfers).
checking wallet vs contract
That one is pretty easy, since there is bytecode if and only if the address is that of a contract.
For example, with web3.js v1.2.1, await web3.eth.getCode(address);
returns "0x"
if and only if there is no bytecode (if and only if address
is NOT the address of a contract).