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!