TransWikia.com

Why can't contracts make API calls?

Ethereum Asked by eth on November 22, 2021

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?

3 Answers

You can actually take in data from the internet. You just need someone to hand it to your contract. How can you trust that person? Use something like Provable. https://provable.xyz This is an idea that uses TLS Notary to guarantee the answer is authentic from the web server.

I found it because I was originally thinking of doing the same thing with TLS Notary. I messaged Vitalik on reddit back on August 22, 2015 about it. He said this:

Using ethereum contracts to verify HTTPS sessions is theoretically a cool idea; my main concern is that the EVM right now may be too slow to implement it. If you want to try, feel free to do the research and see exactly how much work it would take to do it; perhaps it might be possible within 3m gas and I would love to see the results myself.

I'm excited someone had the same idea I had and has already turned it into a thing. If only all development was this easy!

Answered by linagee on November 22, 2021

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.

Answered by Tjaden Hess on November 22, 2021

I believe this was designed as a feature to minimize the burden on the network and reduce resources. There are several solutions if you want to "api call on a contract":

http://www.ethereum-alarm-clock.com/

Source: https://forum.ethereum.org/discussion/3571/ethereum-alarm-clock-call-scheduling-for-contracts

pipermerriam Posts: 10Member ✭ September 2015 in General Project Discussion (non-technical) I'm proud to announce the launch of the Ethereum Alarm Clock service.

http://www.ethereum-alarm-clock.com/

The Alarm service facilitates scheduling contract function calls for a specified block number in the future. The current release should be considered alpha software.

Schedule contract function calls to be executed at a specified block in the future. Trustless. No administrative API's or special access granted to anyone, including myself. Published verifiable source code. Lots of documentation with examples. I'm very interested to hear people's feedback. Feel free to send me a message at pipermerriam on gitter.

Answered by high110 on November 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP