1

There are three types of transactions:

  1. Ether transfer from one EOA to another
  2. Contract creation
  3. 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.

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")
}
  • Why > 2, not > 0? – sinoTrinity Apr 19 '18 at 16:38
  • "0x" is present for externally owned account. – Ayushya Apr 19 '18 at 16:40
  • Oh, u mean getCode().length > 2. – sinoTrinity Apr 19 '18 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.