Contract API Limitations – Why Can’t Ethereum Contracts Make API Calls?

contract-designexternal-apiSecurity

The model that contracts can only accept and process data, instead of also being able to retrieve data from the Internet, seems limiting (even if not, it's less direct).
If a concern is that data or the Internet is unreliable, couldn't a contract be programmed to handle such cases?

Are there fundamental technical limitations that led to Ethereum contracts not being able to "access the Internet" directly?

Best Answer

The Ethereum blockchain was designed to be entirely deterministic. This means, that if I took the whole history of the network, then replayed it on my computer, I should always end up with the correct state.

Since the internet is non-deterministic and changes over time, then every time I replayed all of the transactions on the network, I would receive a different answer.

Determinism is important so that nodes can come to a consensus. If there were a contract that required the number of upvotes on this question, the value could differ from time to time or even place to place, causing nodes in the future or without access to this site to reach different conclusions about the state of the network, thus breaking the consensus.

By requiring that every data input is initiated through an external transaction, we can be sure that the blockchain itself contains all of the information required to verify itself. This process of gathering off-chain data and then pasting it to the blockchain, is known as working with an oracle.

There are several oracle services which allow for a smart-contract to look like it's making an API call, however the oracle is actually making the API calls off-chain and posting the result on-chain for smart contracts to use. Some of these include Chainlink, Provable, BandChain, and Tellor.

Related Topic