-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (30 loc) · 1.03 KB
/
index.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
const { Alchemy, Network, Wallet, Utils } = require('alchemy-sdk');
require('dotenv').config();
const { TEST_API_KEY, TEST_PRIVATE_KEY } = process.env;
const settings = {
apiKey: TEST_API_KEY,
network: Network.ETH_GOERLI,
};
const alchemy = new Alchemy(settings);
let wallet = new Wallet(TEST_PRIVATE_KEY);
async function main() {
const nonce = await alchemy.core.getTransactionCount(
wallet.address,
'latest'
);
let transaction = {
to: '0x0a4402115f4904d9ba8d84dbeb8031e5b0a777f6',//choose any address!,
value: Utils.parseEther('0.001'), // 0.001 worth of ETH being sent
gasLimit: '21000',
maxPriorityFeePerGas: Utils.parseUnits('5', 'gwei'),
maxFeePerGas: Utils.parseUnits('20', 'gwei'),
nonce: nonce,
type: 2,
chainId: 5, // göerli transaction
};
let rawTransaction = await wallet.signTransaction(transaction);
console.log('Raw tx: ', rawTransaction);
let tx = await alchemy.core.sendTransaction(rawTransaction);
console.log(`https://goerli.etherscan.io/tx/${tx.hash}`);
}
main();