<pre><code>ExBudget {\n    mem: 21352,\n    cpu: 7284156,\n}
</code></pre>
<p>This part of the error message suggests it has already performed some computation.</p>
<p>is likely the error is not related to the Redeemer itself, but maybe some error in the contract code.</p>
<p>If you could provide the aiken source it would help to solve the problem</p>

CC BY-SA 4.0
2024-07-10T14:15:42.007Z
I added their validator script above. I am able to lock funds at the address and view the beneficiary's UTxO
tyvan266
CC BY-SA 4.0
2024-07-10T10:09:05.433Z
2024-07-10T10:09:05.433Z
Michele Nuzzi
<p>I was able to solve my issue by removing the <code>must_be_signed_by</code>
helper function from the aiken validator, and instead calling <code>list.has</code> directly. Nonetheless, I'm curious why the re-factoring fails, as it appears to work in the lectures.</p>
<hr />
<p>error at the tx construction:</p>
<pre><code>const tx = await lucid 
    .newTx()
    .addSigner(bob_addr)               
    .validFrom(now)             
    .collectFrom([ourUTxO], Data.void())   // &lt;-- no redeemer 
    .attachSpendingValidator(validator)
    .complete()
</code></pre>
<p>returns:</p>
<pre><code>error: Uncaught (in promise) &quot;Redeemer (Spend, 0): Type mismatch expected 'data' got 'bytestring'\n\nExBudget {\n    mem: 21352,\n    cpu: 7284156,\n}\n\n&quot;
</code></pre>
<p>More code leading up:</p>
<pre><code>
const DatumSchema = Data.Object({
    beneficiary: Data.Bytes(),
    deadline: Data.Integer() 
});


type Datum = Data.Static&lt;typeof DatumSchema&gt;;
const Datum = DatumSchema as unknown as Datum;    


// Load validator
const plutusJSON = JSON.parse(await Deno.readTextFile(&quot;plutus.json&quot;));

const validator: SpendingValidator = {
    type: &quot;PlutusV2&quot;,
    script: plutusJSON.validators.filter((val: any) =&gt; val.title == &quot;lesson2/vesting.vesting&quot;)[0].compiledCode
}

// Query utxos at vesting validator for beneficiary 
const validatorAddr = await lucid.utils.validatorToAddress(validator);
const utxos = await lucid.utxosAt(validatorAddr);
console.log(&quot;Vesting validator address:\n&quot;, validatorAddr);


const bob = await Deno.readTextFile(&quot;assets/bob-pk&quot;);
const priv = PrivateKey.from_bech32(bob);
const pkh = priv.to_public().hash().to_hex(); 

const ourUTxO = utxos.find(utxo =&gt; Data.from(utxo.datum || &quot;&quot;, Datum).beneficiary == pkh);

</code></pre>
<p>And the corresponding Aiken validator code:</p>
<pre><code>type PKH =
  Hash&lt;Blake2b_224, VerificationKey&gt;


type VestingDatum {
  VestingDatum { beneficiary: PKH, deadline: PosixTime }
}

validator {
  fn vesting(datum: VestingDatum, _r, ctx: ScriptContext) -&gt; Bool {
    when ctx.purpose is {
      Spend(_) -&gt; and {
          must_be_signed_by(
            ctx.transaction.extra_signatories,
            datum.beneficiary,
          ),
          must_be_after_deadline(ctx.transaction.validity_range, datum.deadline),
        }
      _ -&gt; False
    }
  }
}

fn must_be_signed_by(people_that_signed, beneficiary) {
  list.has(people_that_signed, beneficiary)
}

fn must_be_after_deadline(range: ValidityRange, deadline: PosixTime) {
  when range.lower_bound.bound_type is {
    Finite(tx_earliest_time) -&gt; deadline &lt;= tx_earliest_time
    _ -&gt; False
  }
}

</code></pre>

<plutus-pioneer-program><lucid><aiken>
Type mismatch error in Lucid / Aiken
# Type mismatch error in Lucid / Aiken

(Asked by: username_0 on 2024-07-07)

I was able to solve my issue by removing the must_be_signed_by
helper function from the aiken validator, and instead calling list.has directly. Nonetheless, I'm curious why the re-factoring fails, as it appears to work in the lectures.

error at the tx construction:
const tx = await lucid 
    .newTx()
    .addSigner(bob_addr)               
    .validFrom(now)             
    .collectFrom([ourUTxO], Data.void())   // <-- no redeemer 
    .attachSpendingValidator(validator)
    .complete()

returns:
error: Uncaught (in promise) "Redeemer (Spend, 0): Type mismatch expected 'data' got 'bytestring'\n\nExBudget {\n    mem: 21352,\n    cpu: 7284156,\n}\n\n"

More code leading up:

const DatumSchema = Data.Object({
    beneficiary: Data.Bytes(),
    deadline: Data.Integer() 
});


type Datum = Data.Static;
const Datum = DatumSchema as unknown as Datum;    


// Load validator
const plutusJSON = JSON.parse(await Deno.readTextFile("plutus.json"));

const validator: SpendingValidator = {
    type: "PlutusV2",
    script: plutusJSON.validators.filter((val: any) => val.title == "lesson2/vesting.vesting")[0].compiledCode
}

// Query utxos at vesting validator for beneficiary 
const validatorAddr = await lucid.utils.validatorToAddress(validator);
const utxos = await lucid.utxosAt(validatorAddr);
console.log("Vesting validator address:\n", validatorAddr);


const bob = await Deno.readTextFile("assets/bob-pk");
const priv = PrivateKey.from_bech32(bob);
const pkh = priv.to_public().hash().to_hex(); 

const ourUTxO = utxos.find(utxo => Data.from(utxo.datum || "", Datum).beneficiary == pkh);


And the corresponding Aiken validator code:
type PKH =
  Hash


type VestingDatum {
  VestingDatum { beneficiary: PKH, deadline: PosixTime }
}

validator {
  fn vesting(datum: VestingDatum, _r, ctx: ScriptContext) -> Bool {
    when ctx.purpose is {
      Spend(_) -> and {
          must_be_signed_by(
            ctx.transaction.extra_signatories,
            datum.beneficiary,
          ),
          must_be_after_deadline(ctx.transaction.validity_range, datum.deadline),
        }
      _ -> False
    }
  }
}

fn must_be_signed_by(people_that_signed, beneficiary) {
  list.has(people_that_signed, beneficiary)
}

fn must_be_after_deadline(range: ValidityRange, deadline: PosixTime) {
  when range.lower_bound.bound_type is {
    Finite(tx_earliest_time) -> deadline <= tx_earliest_time
    _ -> False
  }
}

**Tags:** plutus-pioneer-program, lucid, aiken

---

## 1 answers

### Answer by username_1 on 2024-07-10. Score: 0 | Accepted answer

ExBudget {\n    mem: 21352,\n    cpu: 7284156,\n}

This part of the error message suggests it has already performed some computation.
is likely the error is not related to the Redeemer itself, but maybe some error in the contract code.
If you could provide the aiken source it would help to solve the problem

> **Comments:**
> **username_0**: I added their validator script above. I am able to lock funds at the address and view the beneficiary's UTxO  

---

