<p>You can't call API services directly from the smart contract, and this is not something that the &quot;IOG has yet to put that functionality in&quot;;</p>
<p>the same behaviour is not possible in any other smart contract programming language for security reasons.</p>
<p>with that being said there are a few options you could use:</p>
<h1>get the data from the off-chain (bad)</h1>
<p>you could get the data from the Redeemer; so that the user is telling you the information you need.</p>
<p>this approach is bad because the user could send any redeemer to the script, and you have no way to check the information is true</p>
<p>as an example say you want to access the history of the past user transactions</p>
<p>the user can easily omit (or add) some transactions and you have no way to check that is true.</p>
<p>since ANYONE can write off-chain code to interact with the smart contract you cannot trust the input form the redeemer</p>
<h1>Implement an Oracle</h1>
<p>You could write a smart contract that keeps on a recognizable UTxO the data you need as Datum; then include that UTxO in the tx input of the smart contract you need the data for.</p>
<p>this way you access the data you need by reading any datum from the input.</p>
<p>now the trust is put only in the person that is able to update the oracle, and no longer in ANYONE in the world</p>
<p>the <a href="https://www.youtube.com/watch?v=U7DCPLqolds&amp;list=PLNEK_Ejlx3x28gErogJ6iITWcvL3JdpQB&amp;index=2" rel="nofollow noreferrer">Plutus Pioneer Program, iteration #2, lesson 6</a> might help to have a better idea about Oracles</p>

CC BY-SA 4.0
2022-06-19T14:00:18.127Z
2022-06-19T14:00:18.127Z
Michele Nuzzi
<p>There are two points to note:</p>
<ol>
<li><p>if you have access keys (such as the blockfrost project_id) you don't want to publish these.</p>
</li>
<li><p>you normally want to push the data into the contract by using the datum or pramterisation.</p>
</li>
</ol>
<p>This means you might be well advised to put that processing on off-chain servers and figure out the input you want to send to the contract and proceed accordingly.</p>

CC BY-SA 4.0
2022-06-19T17:22:27.933Z
It is good to remember that all on-chain scripts are passive. This means that the do not compute anything, they *validate* only. A computer can query something, a validation process can only check whether something is done correctly.
Fermat
CC BY-SA 4.0
2022-06-18T22:52:25.270Z
2022-06-18T22:52:25.270Z
KryptoKing
<p>I just spent a few days trying to find a way to access account data from a smart contract using only plutus. Turns out IOG has yet to put that functionality in (at least that's how I understand it) but I no I can get info from the node and therefore from a service like blockfrost.</p>
<p>How do I get that data and have it update regularly until the contract validates?</p>

<cardano-node><api><blockfrost><smart-contract>
How to securely call Blockfrost or other API service from Smart Contract?
# How to securely call Blockfrost or other API service from Smart Contract?

(Asked by: username_0 on 2022-06-18)

I just spent a few days trying to find a way to access account data from a smart contract using only plutus. Turns out IOG has yet to put that functionality in (at least that's how I understand it) but I no I can get info from the node and therefore from a service like blockfrost.

How do I get that data and have it update regularly until the contract validates?

**Tags:** cardano-node, api, blockfrost, smart-contract

---

## 2 answers

### Answer by username_1 on 2022-06-19. Score: 4 | Accepted answer

You can't call API services directly from the smart contract, and this is not something that the "IOG has yet to put that functionality in";

the same behaviour is not possible in any other smart contract programming language for security reasons.

with that being said there are a few options you could use:

# get the data from the off-chain (bad)

you could get the data from the Redeemer; so that the user is telling you the information you need.

this approach is bad because the user could send any redeemer to the script, and you have no way to check the information is true

as an example say you want to access the history of the past user transactions

the user can easily omit (or add) some transactions and you have no way to check that is true.

since ANYONE can write off-chain code to interact with the smart contract you cannot trust the input form the redeemer

# Implement an Oracle

You could write a smart contract that keeps on a recognizable UTxO the data you need as Datum; then include that UTxO in the tx input of the smart contract you need the data for.

this way you access the data you need by reading any datum from the input.

now the trust is put only in the person that is able to update the oracle, and no longer in ANYONE in the world

the [Plutus Pioneer Program, iteration #2, lesson 6](https://www.youtube.com/watch?v=U7DCPLqolds&list=PLNEK_Ejlx3x28gErogJ6iITWcvL3JdpQB&index=2) might help to have a better idea about Oracles


---

### Answer by username_0 on 2022-06-18. Score: 0

There are two points to note:

1. if you have access keys (such as the blockfrost project\_id) you don't want to publish these.
2. you normally want to push the data into the contract by using the datum or pramterisation.

This means you might be well advised to put that processing on off-chain servers and figure out the input you want to send to the contract and proceed accordingly.

> **Comments:**
> **username_2**: It is good to remember that all on-chain scripts are passive. This means that the do not compute anything, they *validate* only. A computer can query something, a validation process can only check whether something is done correctly.  

---

