-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWallet.js
29 lines (22 loc) · 800 Bytes
/
Wallet.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
require('dotenv').config();
const Web3 = require('web3');
const apiKey = process.env['apiKey'];
const network = 'sepolia';
const node = `https://eth.getblock.io/${apiKey}/${network}/`;
const web3 = new Web3(node);
const accountTo = web3.eth.accounts.create();
const privateKey = process.env['privateKey'];
const accountFrom = web3.eth.accounts.privateKeyToAccount(privayeKey);
const createSignedTx = async(rawTx)=>{
rawTx.gas = await web3.eth.estimateGas(rawTx);
return await accountFrom.signTransaction(rawTx);
}
const sendSignedTx = async(signedTx)=>{
web3.eth.sendSignedTransaction(signedTx.rawTransaction).then(console.log)
}
const amountTo="0.01"
const rawTx = {
to:accountTo.address,
value:web3.utils.toWei(amountTo,"ether")
}
createSignedTx(rawTx).then(sendSignedTx)