-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlock.js
More file actions
42 lines (34 loc) · 1.01 KB
/
lock.js
File metadata and controls
42 lines (34 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { mConStr0 } from "@meshsdk/common";
import { deserializeAddress } from "@meshsdk/core";
import {
getTxBuilder,
owner_wallet,
beneficiary_wallet,
scriptAddr,
} from "./common.js";
async function depositFundTx(amount, lockUntilTimeStampMs) {
const utxos = await owner_wallet.getUtxos();
const txBuilder = getTxBuilder();
await txBuilder
.txOut(scriptAddr, amount)
.txOutInlineDatumValue(mConStr0([]))
.changeAddress(owner_wallet.addresses.baseAddressBech32)
.selectUtxosFrom(utxos)
.complete();
return txBuilder.txHex;
}
async function main() {
const assets = [
{
unit: "lovelace",
quantity: "3000000",
},
];
const lockUntilTimeStamp = new Date();
lockUntilTimeStamp.setMinutes(lockUntilTimeStamp.getMinutes() + 10);
const unsignedTx = await depositFundTx(assets, lockUntilTimeStamp.getTime());
const signedTx = await owner_wallet.signTx(unsignedTx);
const txHash = await owner_wallet.submitTx(signedTx);
console.log("txHash", txHash);
}
main();