forked from deprecated-near-examples/transaction-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send-batch-txs.js
67 lines (51 loc) · 1.52 KB
/
send-batch-txs.js
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
65
66
67
const BN = require('bn.js');
const {
connect,
utils,
keyStores,
transactions
} = require('near-api-js');
// Wallet config
const WALLET_ACCOUNT_ID = 'my-account.testnet';
const privateKey = process.env.SENDER_PRIVATE_KEY;
const TOKEN_CONTRACT_ID = 'oct.beta_oct_relay.testnet';
// Target account to transfer token
const TARGET_ACCOUNT_ID = 'sub-acct2.my-account.testnet';
// Network config
const NETWORK_ID = 'testnet';
const DEFAULT_GAS = new BN('120000000000000');
const keyPair = utils.KeyPair.fromString('ed25519:' + privateKey);
const keyStore = new keyStores.InMemoryKeyStore();
keyStore.setKey(NETWORK_ID, WALLET_ACCOUNT_ID, keyPair);
const nearConfig = {
networkId: NETWORK_ID,
keyStore,
nodeUrl: `https://rpc.${NETWORK_ID}.near.org`,
walletUrl: `https://wallet.${NETWORK_ID}.near.org`,
helperUrl: `https://helper.${NETWORK_ID}.near.org`,
}
async function main() {
const near = await connect(nearConfig);
const account = await near.account(WALLET_ACCOUNT_ID);
const depositTx = transactions.functionCall(
'storage_deposit',
{ account_id: TARGET_ACCOUNT_ID },
DEFAULT_GAS,
new BN('12500000000000000000000')
);
const transferTx = transactions.functionCall(
'ft_transfer',
{
receiver_id: TARGET_ACCOUNT_ID,
amount: new BN(1).mul(new BN(10).pow(new BN(17))).toString()
},
DEFAULT_GAS,
1
);
const receipt = await account.signAndSendTransaction({
receiverId: TOKEN_CONTRACT_ID,
actions: [depositTx, transferTx]
});
console.log(receipt);
}
main();