2

I'm using ruby and would like to find out if an address is a contract one that can potentially take a lot of gas to transfer money to (and possibly failed in the middle).

In this: Using EVM assembly to get the address' code size

They suggesting to use this code:

function isContract(address addr) returns (bool) {
  uint size;
  assembly { size := extcodesize(addr) }
  return size > 0;
}

I think this is to be executed inside ETH miner itself? If I want to perform a simple check on my browser/Ruby on Rails server, how should I do it?

Achala Dissanayake
  • 5,819
  • 15
  • 28
  • 38

1 Answers1

1

You can use the Ethereum node's RPC interface described here: https://github.com/ethereum/wiki/wiki/JSON-RPC. You're interested in this function here: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcode. You can use curl to request the data.

Thomas Jay Rush
  • 9,943
  • 4
  • 31
  • 72