There are three types of transactions:
- Ether transfer from one EOA to another
- Contract creation
- Contract call
2 can be easily identified since it's "to" field is empty. How to differentiate 1 & 3? This post separates 2 from 3.
There are three types of transactions:
2 can be easily identified since it's "to" field is empty. How to differentiate 1 & 3? This post separates 2 from 3.
In order to differentiate between 1 and 3, you can check if there is any code at the to address.
if(web3.eth.getCode("0xa5Acc472597C1e1651270da9081Cc5a0b38258E3").length > 2){
console.log("Sent to contract")
}
else{
console.log("Sent to a externally owned address")
}
> 2, not> 0? – sinoTrinity Apr 19 '18 at 16:38getCode().length > 2. – sinoTrinity Apr 19 '18 at 16:41