<p>it's a bit hard to tell from where your error might come from, but your error simply means that you tried to use something that wasn't properly encoded in hex.
Therefore, the error message arises that the character <code>s</code> was read, but it's indeed not a valid character of a hex-encoding.</p>
<p>This problem often occurs for me, when I have forgotten to convert the name of a token from UTF-8 to hex.
This could also be the issue for you, i.e., you have a token starting with <code>s</code> in its name, and now you want to use the string encoded with utf-8 in, e.g., your datum. Instead, the token name should be converted to hex before using it as part of your datum.</p>

CC BY-SA 4.0
2023-07-24T23:04:13.143Z
2023-07-24T23:04:13.143Z
Chrissi
<p>I am getting an issue when creating a Lucid transaction and calling <code>payToContract</code>
I have created the datum and it is erroring on the line that converts this datum <code>toHex</code></p>
<p>With the following error: <strong>Error: encoding/hex: invalid byte: s</strong>
This happens every time I run the logic,</p>
<p>Code to build the datum</p>
<pre><code>onst deadline = Date.now() + 6 * 60 * 60 * 1000; // in 6 hours
const datum = new RequestDatum(
  new RequestMetadaDatum(
    ownerAddress,
    ownerAddress.payment_cred()!, // the owner whe can reclaim the request
    bigint.from_str(deadline.toFixed(0)), // deadline in posix time
    assetClassFromUnit('lovelace'), // the LP assets need to be ordered
    assetClassFromUnit(assetSubject)
  ),
  new SwapAction(SwapDirection.BTOA, bigint.from_str(minimumAmountTokenOut.toString()))
).to_plutus_data();
</code></pre>
<p>Transaction code</p>
<pre><code>// Create a transaction that creates a swap request
const unsignedTx = await this._lucid
  .newTx()
  .payToContract(this._lucid.utils.credentialToAddress(this._lucid.utils.scriptHashToCredential(REQUEST_SCRIPT_HASH)), toHex(datum.to_bytes()), {
    lovelace: BigInt(lockedCoins.to_str()),
    assetSubject: quantityOfToken,
  })
  .complete();
</code></pre>
<p>This is an implementation using the Wingriders Blockfrost Adapter found here: <a href="https://github.com/WingRiders/dex-blockfrost-adapter/blob/main/examples/swap-fe-vanilla-js/src/swap.ts" rel="nofollow noreferrer">https://github.com/WingRiders/dex-blockfrost-adapter/blob/main/examples/swap-fe-vanilla-js/src/swap.ts</a></p>
<p>Would appreciate any guidance here, thanks!</p>

<plutus><cardano-serialization-lib><utxo><lucid>
Error: encoding/hex: invalid byte: s When using Lucid calling payToContract
# Error: encoding/hex: invalid byte: s When using Lucid calling payToContract

(Asked by: username_0 on 2023-06-11)

I am getting an issue when creating a Lucid transaction and calling payToContract
I have created the datum and it is erroring on the line that converts this datum toHex
With the following error: Error: encoding/hex: invalid byte: s
This happens every time I run the logic,
Code to build the datum
onst deadline = Date.now() + 6 * 60 * 60 * 1000; // in 6 hours
const datum = new RequestDatum(
  new RequestMetadaDatum(
    ownerAddress,
    ownerAddress.payment_cred()!, // the owner whe can reclaim the request
    bigint.from_str(deadline.toFixed(0)), // deadline in posix time
    assetClassFromUnit('lovelace'), // the LP assets need to be ordered
    assetClassFromUnit(assetSubject)
  ),
  new SwapAction(SwapDirection.BTOA, bigint.from_str(minimumAmountTokenOut.toString()))
).to_plutus_data();

Transaction code
// Create a transaction that creates a swap request
const unsignedTx = await this._lucid
  .newTx()
  .payToContract(this._lucid.utils.credentialToAddress(this._lucid.utils.scriptHashToCredential(REQUEST_SCRIPT_HASH)), toHex(datum.to_bytes()), {
    lovelace: BigInt(lockedCoins.to_str()),
    assetSubject: quantityOfToken,
  })
  .complete();

This is an implementation using the Wingriders Blockfrost Adapter found here: https://github.com/WingRiders/dex-blockfrost-adapter/blob/main/examples/swap-fe-vanilla-js/src/swap.ts
Would appreciate any guidance here, thanks!

**Tags:** plutus, cardano-serialization-lib, utxo, lucid

---

## 1 answers

### Answer by username_1 on 2023-07-24. Score: 1

it's a bit hard to tell from where your error might come from, but your error simply means that you tried to use something that wasn't properly encoded in hex.
Therefore, the error message arises that the character `s` was read, but it's indeed not a valid character of a hex-encoding.

This problem often occurs for me, when I have forgotten to convert the name of a token from UTF-8 to hex.
This could also be the issue for you, i.e., you have a token starting with `s` in its name, and now you want to use the string encoded with utf-8 in, e.g., your datum. Instead, the token name should be converted to hex before using it as part of your datum.


---

