How to check for a smart contract?

Faced a problem when generating automatic transactions:

  • usually I send the parameter Gas Limit = 21000, but on wallets that have a smart contract, this value is not enough, as a result - the transaction flies into the error “Warning! Error encountered during contract execution [Out of gas]”.
    Can I somehow (automatically) detect the presence of a smart contract on my wallet so that I can increase the Gas Limit value?
    Perhaps there is a way to find out the required amount of Gas Limit for a successful transaction?
    As I understand it, the estimateGas method in this case will not return a reliable value …

Hey @YMCHANGE , I recommend reading this here to determine if a contract is an “Externally Owned Account” or a smart contract. They have 2 solutions there, one with solidity and one using eth.getCode which can be called through Infura. A contract and a EOA will have different bytecode lengths.