<p>The context includes two parts: <code>TxInfo</code> and <code>ScriptPurpose</code>.</p>
<pre><code>data ScriptContext = ScriptContext{
    scriptContextTxInfo :: TxInfo, 
    scriptContextPurpose :: ScriptPurpose 
}
</code></pre>
<p>When people are talking about the script context, they are often referring to the data in <code>TxInfo</code> found <a href="https://github.com/input-output-hk/plutus/blob/90d76651aea0716e11446c8ac23cd0803c0f0d3a/plutus-ledger-api/src/Plutus/V2/Ledger/Contexts.hs#L78-L91" rel="nofollow noreferrer">here</a>:</p>
<pre><code>data TxInfo = TxInfo
    { txInfoInputs      :: [TxInInfo] -- ^ Transaction inputs
    , txInfoOutputs     :: [TxOut] -- ^ Transaction outputs
    , txInfoFee         :: Value -- ^ The fee paid by this transaction.
    , txInfoMint        :: Value -- ^ The 'Value' minted by this transaction.
    , txInfoDCert       :: [DCert] -- ^ Digests of certificates included in this transaction
    , txInfoWdrl        :: Map StakingCredential Integer -- ^ Withdrawals
    , txInfoValidRange  :: POSIXTimeRange -- ^ The valid range for the transaction.
    , txInfoSignatories :: [PubKeyHash] -- ^ Signatures provided with the transaction, attested that they all signed the tx
    , txInfoRedeemers   :: Map ScriptPurpose Redeemer
    , txInfoData        :: Map DatumHash Datum
    , txInfoId          :: TxId
}
</code></pre>
<p>This includes information about the entire <em>transaction</em>. So if you are using multiple scripts you can see what is being spent/minted/burned/etc with all the scripts you are accessing. Many smart contracts are made up of multiple scripts, all accessed at the same time. At the risk of stating the obvious, understanding what information is available for all the scripts in a transaction, i.e. the <code>TxInfo</code>, is fundamental to architecting smart contracts with Plutus.</p>

CC BY-SA 4.0
2021-10-29T17:26:05.930Z
Thank you for the great and clear answer. Looking at the data structures is indeed a very good way to look at this.
FTM
CC BY-SA 4.0
2021-10-28T16:57:42.480Z
2022-04-21T03:29:10.453Z
2022-04-21T03:29:10.453Z
Mitchell Turner
<p>Aiming to contribute to the great answer from Mitchell, I'll add this:</p>
<p><strong>Script context</strong> can be understood like the summary of the transaction and can be used to validate it. This includes all inputs <code>txInfoInputs</code> and outputs <code>txInfoOutputs</code> (<a href="https://staging.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V2-Ledger-Contexts.html#v:ScriptContext" rel="nofollow noreferrer">and more!</a>) of the transaction, those inputs and outputs are UTxOs.</p>
<p>Let's take an example from <a href="https://plutus-pioneer-program.readthedocs.io/en/latest/pioneer/week6.html" rel="nofollow noreferrer">Lesson 06</a> (on Oracles) of the Plutus Pioneer Program:</p>
<p><a href="https://i.sstatic.net/yQO7P.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/yQO7P.jpg" alt="enter image description here" /></a></p>
<p>In this example we can find two transactions, let's examine the first one:</p>
<p><strong>Tx 1</strong>: this transaction contains 3 inputs <code>txInfoInputs</code> and 3 outputs <code>txInfoOutputs</code></p>
<ul>
<li>Inputs: UTxOs consumed by the current transaction</li>
</ul>
<ol>
<li>UTxO of Oracle script</li>
<li>UTxO of Swap script</li>
<li>UTxO of Buyer</li>
</ol>
<ul>
<li>Outputs: UTxOs generated by the current transaction</li>
</ul>
<ol>
<li>UTxO of Oracle script</li>
<li>UTxO of Seller</li>
<li>UTxO of Buyer</li>
</ol>
<p>You can use all of those UTxOs to run any kind of validation from your validator script. So far, that's related to two fields of <code>TxInfo</code>. But there is more to explore: <a href="https://cardano.stackexchange.com/a/4330/1231">Mitchell answer</a>, as you can also combine your validation with a Minting policy for example.</p>
<p>For more information, you can check following links:</p>
<ul>
<li><a href="https://plutus-pioneer-program.readthedocs.io/en/latest/pioneer/week3.html#" rel="nofollow noreferrer">Week 03 - Script Context</a></li>
<li><a href="https://www.youtube.com/watch?v=6_rfCCY9_gY&amp;t=55s" rel="nofollow noreferrer">Script contexts from Lars Brünjes</a></li>
</ul>

CC BY-SA 4.0
2021-10-28T18:26:22.293Z
2022-04-06T23:30:38.143Z
2022-04-06T23:30:38.143Z
georgeos
<p>I believe the best way to answer this question would be to give examples of the type of information that the script context could contain.</p>

<plutus><plutustx><context>
What exactly is the script context in Plutus context?
# What exactly is the script context in Plutus context?

(Asked by: username_0 on 2021-10-28)

I believe the best way to answer this question would be to give examples of the type of information that the script context could contain.

**Tags:** plutus, plutustx, context

---

## 2 answers

### Answer by username_1 on 2021-10-28. Score: 4 | Accepted answer

The context includes two parts: TxInfo and ScriptPurpose.
data ScriptContext = ScriptContext{
    scriptContextTxInfo :: TxInfo, 
    scriptContextPurpose :: ScriptPurpose 
}

When people are talking about the script context, they are often referring to the data in TxInfo found here:
data TxInfo = TxInfo
    { txInfoInputs      :: [TxInInfo] -- ^ Transaction inputs
    , txInfoOutputs     :: [TxOut] -- ^ Transaction outputs
    , txInfoFee         :: Value -- ^ The fee paid by this transaction.
    , txInfoMint        :: Value -- ^ The 'Value' minted by this transaction.
    , txInfoDCert       :: [DCert] -- ^ Digests of certificates included in this transaction
    , txInfoWdrl        :: Map StakingCredential Integer -- ^ Withdrawals
    , txInfoValidRange  :: POSIXTimeRange -- ^ The valid range for the transaction.
    , txInfoSignatories :: [PubKeyHash] -- ^ Signatures provided with the transaction, attested that they all signed the tx
    , txInfoRedeemers   :: Map ScriptPurpose Redeemer
    , txInfoData        :: Map DatumHash Datum
    , txInfoId          :: TxId
}

This includes information about the entire transaction. So if you are using multiple scripts you can see what is being spent/minted/burned/etc with all the scripts you are accessing. Many smart contracts are made up of multiple scripts, all accessed at the same time. At the risk of stating the obvious, understanding what information is available for all the scripts in a transaction, i.e. the TxInfo, is fundamental to architecting smart contracts with Plutus.

> **Comments:**
> **username_0**: Thank you for the great and clear answer. Looking at the data structures is indeed a very good way to look at this.  

---

### Answer by username_2 on 2021-10-28. Score: 3

Aiming to contribute to the great answer from Mitchell, I'll add this:

**Script context** can be understood like the summary of the transaction and can be used to validate it. This includes all inputs `txInfoInputs` and outputs `txInfoOutputs` ([and more!](https://staging.plutus.iohkdev.io/doc/haddock/plutus-ledger-api/html/Plutus-V2-Ledger-Contexts.html#v:ScriptContext)) of the transaction, those inputs and outputs are UTxOs.

Let's take an example from [Lesson 06](https://plutus-pioneer-program.readthedocs.io/en/latest/pioneer/week6.html) (on Oracles) of the Plutus Pioneer Program:

[![enter image description here](https://i.sstatic.net/yQO7P.jpg)](https://i.sstatic.net/yQO7P.jpg)

In this example we can find two transactions, let's examine the first one:

**Tx 1**: this transaction contains 3 inputs `txInfoInputs` and 3 outputs `txInfoOutputs`

* Inputs: UTxOs consumed by the current transaction

1. UTxO of Oracle script
2. UTxO of Swap script
3. UTxO of Buyer

* Outputs: UTxOs generated by the current transaction

1. UTxO of Oracle script
2. UTxO of Seller
3. UTxO of Buyer

You can use all of those UTxOs to run any kind of validation from your validator script. So far, that's related to two fields of `TxInfo`. But there is more to explore: [Mitchell answer](https://cardano.stackexchange.com/a/4330/1231), as you can also combine your validation with a Minting policy for example.

For more information, you can check following links:

* [Week 03 - Script Context](https://plutus-pioneer-program.readthedocs.io/en/latest/pioneer/week3.html#)
* [Script contexts from Lars Brünjes](https://www.youtube.com/watch?v=6_rfCCY9_gY&t=55s)


---

