<p>You need to create a deploy file that adds parameters to the plutus script and then generates the plutus script to be submitted to the blockchain.  If you look at the generated file, you will see the following contents including the cborHex.</p>
<pre><code>$ cat vesting.plutus | jq
{
  &quot;type&quot;: &quot;PlutusScriptV2&quot;,
  &quot;description&quot;: &quot;&quot;,
  &quot;cborHex&quot;: &quot;5901e55901e20100003232323232323232323232323232323232323232323232323232323232323232323232323232222533357346660080060040022930b1111919191992999ab9a3370e002900009198168998141981300218048041815a49055653313a200013302833019005300b008302b491055653323a2000123302d133028330160043009008302b4901055653333a200013302833019005300a008302b491055653343a200035573a6ea8004004010c040c038004c03000401400c0048d5d09bac001235742600800246ae84c0080048d5d1180100091aba2375800200800246ae84c02c0048c008c008c0080048d5d098080008009191180219b89002375a0026eb40048ccd5cd000a504a2446601c6eb0c00c0088cdd780080100091aba13002001235744600400246ae88c0080048d5d1180100091aba23002001235744600400246ae88c0080048d5d1180100091aba23002001235573c6ea800488c8ccc00400400c0088894ccd5cd1aba300214a02a666ae68c004d5d08010a51133300300335744004002002464466e20008dd68009bad00122335738600c66008002a6006004004426006666ae6800524104747275650049010566616c736500232230043372c004600a002600600246ea4dcc00091b99375c00244a666ae694008540045281&quot;
}
</code></pre>
<p>Here is the old Haskell PlutusTx V2 Way:</p>
<p><a href="https://github.com/lley154/traceability-smart-contract/blob/main/src/Traceability/V2/Deploy.hs" rel="nofollow noreferrer">https://github.com/lley154/traceability-smart-contract/blob/main/src/Traceability/V2/Deploy.hs</a></p>
<p>Here is the better Helios way:</p>
<p><a href="https://github.com/lley154/helios-examples/blob/main/vesting/src/deploy-vesting.js" rel="nofollow noreferrer">https://github.com/lley154/helios-examples/blob/main/vesting/src/deploy-vesting.js</a></p>
<p>Find our more about Helios here:</p>
<p>Helios Github repo <a href="https://github.com/Hyperion-BT/Helios" rel="nofollow noreferrer">https://github.com/Hyperion-BT/Helios</a></p>
<p>Cardano Smart Contracts with Helios Book:
<a href="https://rads.stackoverflow.com/amzn/click/com/B0BTBK6YM7" rel="nofollow noreferrer" rel="nofollow noreferrer">https://www.amazon.com/Cardano-Smart-Contracts-Helios-Lawrence-ebook/dp/B0BTBK6YM7/</a></p>
<p>Helios examples:
<a href="https://github.com/lley154/helios-examples" rel="nofollow noreferrer">https://github.com/lley154/helios-examples</a></p>

CC BY-SA 4.0
2023-02-13T08:48:03.163Z
Hi, Actually i am implementing onchain code in Plutus and offchain in Mesh library. So i am puzzled about how can i interact with a parameterized onchain code. Like how to generate the CBOR in the case where the parameters have to be passed runTime like UTXO. And also how can i  validate the customized datums made onchain side. E.g. in case of Vesting contract. I created a custom datum with params of deadline (POSIX) and beneficiary (PayPubKeyHash). But when i pass the same datums on offchain side, my script doesnot detect them and gives the error of "MissingRequiredDatums". Kindly guide me.
duaa azhar
CC BY-SA 4.0
2023-02-13T13:30:47.447Z
One of the big advantages of Helios is that you can compile code to plutus on the fly in the browser.  So this inline Helios code can be passed a UTXO from a browser wallet that will be used in a transaction and then on the fly, be compiled into plutus code and submitted with the transaction.   I'll post the code in a answer so it is formatted better.
lley154
CC BY-SA 4.0
2023-02-09T01:52:40.227Z
2023-02-09T01:52:40.227Z
lley154
<p>One of the big advantages of Helios is that you can compile code to plutus on the fly in the browser.  So this inline Helios code can be passed a UTXO from a browser wallet that will be used in a transaction and then on the fly, compiled into plutus code and submitted with the transaction.</p>
<pre><code>...
   // Off-chain code
   // Get wallet UTXOs
   const walletHelper = new WalletHelper(walletAPI);
   const utxos = await walletHelper.pickUtxos(minUTXOVal);
...

   // On-chain code in mintScript variable
   const mintScript =`minting nft
   const TX_ID: ByteArray = #` + utxos[0][0].txId.hex + `
   const txId: TxId = TxId::new(TX_ID)
   const outputId: TxOutputId = TxOutputId::new(txId, ` + utxos[0][0].utxoIdx + `)

   func main(ctx: ScriptContext) -&gt; Bool {
       tx: Tx = ctx.tx;
       mph: MintingPolicyHash = ctx.get_current_minting_policy_hash();
...

    // Off-chain code
    // Compile the helios minting script
    const mintProgram = Program.new(mintScript).compile(optimize);

    // Add the script as a witness to the transaction
    tx.attachScript(mintProgram);
...

</code></pre>
<p><a href="https://github.com/lley154/helios-examples/blob/main/nft/pages/index.tsx" rel="nofollow noreferrer">https://github.com/lley154/helios-examples/blob/main/nft/pages/index.tsx</a></p>
<p>For Datums, you created them during transaction construction and then include them in your transaction.   I’ll use Helios as an example because the code is very easy to understand.</p>
<p>Here is the helios code that gets compiled into plutus code (untyped plutus core).</p>
<p>On-chain code</p>
<pre><code>spending vesting

struct Datum {
    creator: PubKeyHash
    beneficiary: PubKeyHash
    deadline: Time
}

enum Redeemer {
    Cancel
    Claim
}

func main(datum: Datum, redeemer: Redeemer, context: ScriptContext) -&gt; Bool {
    tx: Tx = context.tx;
    now: Time = tx.time_range.start;

    redeemer.switch {
        Cancel =&gt; {
            // Check if deadline hasn't passed
            (now &lt; datum.deadline).trace(&quot;VS1: &quot;) &amp;&amp; 

            // Check that the owner signed the transaction
            tx.is_signed_by(datum.creator).trace(&quot;VS2: &quot;)
        },
        Claim =&gt; {
           // Check if deadline has passed.
           (now &gt; datum.deadline).trace(&quot;VS3: &quot;) &amp;&amp;

           // Check that the beneficiary signed the transaction.
           tx.is_signed_by(datum.beneficiary).trace(&quot;VS4: &quot;)
        }
    }
}
</code></pre>
<p><a href="https://github.com/lley154/helios-examples/blob/main/vesting/src/vesting.hl" rel="nofollow noreferrer">https://github.com/lley154/helios-examples/blob/main/vesting/src/vesting.hl</a></p>
<p>off-chain code</p>
<pre><code>...
   // Construct the datum
   const datum = new ListData([new ByteArrayData(ownerPkh.bytes),
                                 new ByteArrayData(benPkh.bytes),
                                 new IntData(BigInt(deadline.getTime()))]);
   const inlineDatum = Datum.inline(datum);
...

   // Add the destination address and the amount of Ada to lock including a datum
   tx.addOutput(new TxOutput(valAddr, lockedVal, inlineDatum));
</code></pre>
<p><a href="https://github.com/lley154/helios-examples/blob/main/vesting/pages/index.tsx" rel="nofollow noreferrer">https://github.com/lley154/helios-examples/blob/main/vesting/pages/index.tsx</a></p>

CC BY-SA 4.0
2023-02-13T13:39:55.800Z
2023-02-13T13:47:30.227Z
2023-02-13T13:47:30.227Z
lley154
<p>How can i generate the CBOR hex of a plutus smart contract. Does it requires to generate CBOR of onchain code only or both onchain and offchain?
Also if have a smart contract which requires parameters e.g. deadline. to run, then how will i be able to pass that argument with that cbor at the time of deployment of plutus smart contract.
Kindly suggest a recommended way for that and also how to interact efficiently with that CBPOR.</p>

<plutus><cardano-cli><smart-contract><on-chain><cbor>
How to generate CBOR hex of plutus smart contract
# How to generate CBOR hex of plutus smart contract

(Asked by: username_0 on 2023-01-24)

How can i generate the CBOR hex of a plutus smart contract. Does it requires to generate CBOR of onchain code only or both onchain and offchain?
Also if have a smart contract which requires parameters e.g. deadline. to run, then how will i be able to pass that argument with that cbor at the time of deployment of plutus smart contract.
Kindly suggest a recommended way for that and also how to interact efficiently with that CBPOR.

**Tags:** plutus, cardano-cli, smart-contract, on-chain, cbor

---

## 2 answers

### Answer by username_1 on 2023-02-09. Score: -1

You need to create a deploy file that adds parameters to the plutus script and then generates the plutus script to be submitted to the blockchain.  If you look at the generated file, you will see the following contents including the cborHex.
$ cat vesting.plutus | jq
{
  "type": "PlutusScriptV2",
  "description": "",
  "cborHex": "5901e55901e20100003232323232323232323232323232323232323232323232323232323232323232323232323232222533357346660080060040022930b1111919191992999ab9a3370e002900009198168998141981300218048041815a49055653313a200013302833019005300b008302b491055653323a2000123302d133028330160043009008302b4901055653333a200013302833019005300a008302b491055653343a200035573a6ea8004004010c040c038004c03000401400c0048d5d09bac001235742600800246ae84c0080048d5d1180100091aba2375800200800246ae84c02c0048c008c008c0080048d5d098080008009191180219b89002375a0026eb40048ccd5cd000a504a2446601c6eb0c00c0088cdd780080100091aba13002001235744600400246ae88c0080048d5d1180100091aba23002001235744600400246ae88c0080048d5d1180100091aba23002001235573c6ea800488c8ccc00400400c0088894ccd5cd1aba300214a02a666ae68c004d5d08010a51133300300335744004002002464466e20008dd68009bad00122335738600c66008002a6006004004426006666ae6800524104747275650049010566616c736500232230043372c004600a002600600246ea4dcc00091b99375c00244a666ae694008540045281"
}

Here is the old Haskell PlutusTx V2 Way:
https://github.com/lley154/traceability-smart-contract/blob/main/src/Traceability/V2/Deploy.hs
Here is the better Helios way:
https://github.com/lley154/helios-examples/blob/main/vesting/src/deploy-vesting.js
Find our more about Helios here:
Helios Github repo https://github.com/Hyperion-BT/Helios
Cardano Smart Contracts with Helios Book:
https://www.amazon.com/Cardano-Smart-Contracts-Helios-Lawrence-ebook/dp/B0BTBK6YM7/
Helios examples:
https://github.com/lley154/helios-examples

> **Comments:**
> **username_0**: Hi, Actually i am implementing onchain code in Plutus and offchain in Mesh library. So i am puzzled about how can i interact with a parameterized onchain code. Like how to generate the CBOR in the case where the parameters have to be passed runTime like UTXO. And also how can i  validate the customized datums made onchain side. E.g. in case of Vesting contract. I created a custom datum with params of deadline (POSIX) and beneficiary (PayPubKeyHash). But when i pass the same datums on offchain side, my script doesnot detect them and gives the error of "MissingRequiredDatums". Kindly guide me.  
> **username_1**: One of the big advantages of Helios is that you can compile code to plutus on the fly in the browser.  So this inline Helios code can be passed a UTXO from a browser wallet that will be used in a transaction and then on the fly, be compiled into plutus code and submitted with the transaction.   I'll post the code in a answer so it is formatted better.  

---

### Answer by username_1 on 2023-02-13. Score: -1

One of the big advantages of Helios is that you can compile code to plutus on the fly in the browser.  So this inline Helios code can be passed a UTXO from a browser wallet that will be used in a transaction and then on the fly, compiled into plutus code and submitted with the transaction.
...
   // Off-chain code
   // Get wallet UTXOs
   const walletHelper = new WalletHelper(walletAPI);
   const utxos = await walletHelper.pickUtxos(minUTXOVal);
...

   // On-chain code in mintScript variable
   const mintScript =`minting nft
   const TX_ID: ByteArray = #` + utxos[0][0].txId.hex + `
   const txId: TxId = TxId::new(TX_ID)
   const outputId: TxOutputId = TxOutputId::new(txId, ` + utxos[0][0].utxoIdx + `)

   func main(ctx: ScriptContext) -> Bool {
       tx: Tx = ctx.tx;
       mph: MintingPolicyHash = ctx.get_current_minting_policy_hash();
...

    // Off-chain code
    // Compile the helios minting script
    const mintProgram = Program.new(mintScript).compile(optimize);

    // Add the script as a witness to the transaction
    tx.attachScript(mintProgram);
...


https://github.com/lley154/helios-examples/blob/main/nft/pages/index.tsx
For Datums, you created them during transaction construction and then include them in your transaction.   I’ll use Helios as an example because the code is very easy to understand.
Here is the helios code that gets compiled into plutus code (untyped plutus core).
On-chain code
spending vesting

struct Datum {
    creator: PubKeyHash
    beneficiary: PubKeyHash
    deadline: Time
}

enum Redeemer {
    Cancel
    Claim
}

func main(datum: Datum, redeemer: Redeemer, context: ScriptContext) -> Bool {
    tx: Tx = context.tx;
    now: Time = tx.time_range.start;

    redeemer.switch {
        Cancel => {
            // Check if deadline hasn't passed
            (now < datum.deadline).trace("VS1: ") && 

            // Check that the owner signed the transaction
            tx.is_signed_by(datum.creator).trace("VS2: ")
        },
        Claim => {
           // Check if deadline has passed.
           (now > datum.deadline).trace("VS3: ") &&

           // Check that the beneficiary signed the transaction.
           tx.is_signed_by(datum.beneficiary).trace("VS4: ")
        }
    }
}

https://github.com/lley154/helios-examples/blob/main/vesting/src/vesting.hl
off-chain code
...
   // Construct the datum
   const datum = new ListData([new ByteArrayData(ownerPkh.bytes),
                                 new ByteArrayData(benPkh.bytes),
                                 new IntData(BigInt(deadline.getTime()))]);
   const inlineDatum = Datum.inline(datum);
...

   // Add the destination address and the amount of Ada to lock including a datum
   tx.addOutput(new TxOutput(valAddr, lockedVal, inlineDatum));

https://github.com/lley154/helios-examples/blob/main/vesting/pages/index.tsx


---

