-
Notifications
You must be signed in to change notification settings - Fork 9
/
create-htlc.ts
32 lines (29 loc) · 1.25 KB
/
create-htlc.ts
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
import 'dotenv/config';
import { ETH } from '../config';
import { EvmHtlc } from '@layerswap/evm';
async function lock() {
// setup
const { PRIVATE_KEYS, NETWORK } = ETH;
const chainId = 1; // example chain ID
const receiverChainAddress = '0x60f8212132210acDB8E526f31fC84feaC6E9535B'; // example receiver chain address
const client = new EvmHtlc(NETWORK.TEST.sepolia.native.endpoint, NETWORK.TEST.sepolia.native.contractAddress);
const AccountService = client.web3.eth.accounts;
const fromAddress = AccountService.wallet.add(PRIVATE_KEYS.FROM).address;
const toAddress = AccountService.wallet.add(PRIVATE_KEYS.TO).address;
const hashPair = client.createHashPair();
// lock
const result = await client.lock(toAddress, fromAddress, hashPair.secret, 1, chainId, receiverChainAddress);
console.log('----- Lock transaction enlistment completed -----', {
fromAddress: fromAddress,
toAddress: toAddress,
contractId: result.events.EtherTransferInitiated.returnValues.contractId,
transactionHash: result.transactionHash,
proof: hashPair.proof,
secret: hashPair.secret,
contractInfo: await client.getContractInfo(result.events.EtherTransferInitiated.returnValues.contractId),
});
}
async function start() {
await lock();
}
start();