0

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?

2 Answers 2

4

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 might help to have a better idea about Oracles

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.

1
  • 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
    Jun 19, 2022 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.