-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathassetsBag.ts
More file actions
64 lines (51 loc) · 1.67 KB
/
assetsBag.ts
File metadata and controls
64 lines (51 loc) · 1.67 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2026 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
import {
AccountsContractMethod,
CoreContract,
getHname,
IscTransaction,
L2_FROM_L1_GAS_BUDGET,
} from '../src/index.js';
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import { Ed25519Keypair } from '@iota/iota-sdk/keypairs/ed25519';
import { requestIotaFromFaucetV0 } from '@iota/iota-sdk/faucet';
import { IotaClient } from '@iota/iota-sdk/client';
import { CONFIG } from './config.js';
const { L1 } = CONFIG;
const client = new IotaClient({
url: L1.rpcUrl,
});
const keypair = new Ed25519Keypair();
const address = keypair.toIotaAddress();
console.log('Requesting faucet...');
await requestIotaFromFaucetV0({
host: L1.faucetUrl as string,
recipient: address,
});
console.log('Sending...');
// EVM Address
const recipientAddress = process.argv[2];
// Amount to send (1 IOTAs)
const amountToSend = BigInt(1 * 1000000000);
// We also need to place a little more in the bag to cover the L2 gas
const amountToPlace = amountToSend + L2_FROM_L1_GAS_BUDGET;
const iscTx = new IscTransaction(L1);
const bag = iscTx.newBag();
const coin = iscTx.coinFromAmount({ amount: amountToPlace });
iscTx.placeCoinInBag({ coin, bag });
iscTx.createAndSendToEvm({
bag,
transfers: [[IOTA_TYPE_ARG, amountToSend]],
address: recipientAddress,
accountsContract: getHname(CoreContract.Accounts),
accountsFunction: getHname(AccountsContractMethod.TransferAllowanceTo),
});
const transaction = iscTx.build();
transaction.setSender(address);
await transaction.build({ client });
await client.signAndExecuteTransaction({
signer: keypair,
transaction,
});
console.log('Sent!');