2

Recently, I have a question about searching function in blockchain. Blockchain is a distributed database and as a database, there should be some searching functions such as "Select", "Join". I am wondering if I have 10 contracts in my private blockchain, how can I search according to the attribute inside the contracts? Is that the only way to do it, is to have a registration contract.

Thank

2

You are correct, ethereum blockchain is a distributed database but you cannot do any query you want (for example, getting all the transactions for a given account needs you to process the whole blockchain, see this answer for example).

That being said, there are several methods that allow you to get information without using another tool for processing/indexing besides the ethereum node itself. The API is stated in Ethereum JSON-RPC definition, for example:

  • eth_getbalance will allow you, given the contract address, to query for it's address.
  • eth_call is used to send a message to a contract and get information stored within it's state.

I recommend you to take a look at Web3.js which a javascript client. There are good examples here.

| improve this answer | |

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.