const Web3 = require("web3")
const web3 = new Web3(new Web3.providers.HttpProvider("https://bsc-dataseed1.binance.org:443"))
const Tx = require('ethereumjs-tx').Transaction;


const address = 'your_address';
const privateKey = Buffer.from('your_private', 'hex')

const ToAddress = 'where_address';

async function checkBalance() {
try {
web3.eth.getBalance(address).then((balanceInWei) => {
balance = web3.utils.fromWei(balanceInWei);
console.log("Balance", address, "---", balance);
});
} catch (error) {
console.log(error);
}
}

checkBalance();

web3.eth.getTransactionCount(address, (err, txCount) => {
// Build a transaction
const txObject = {
nonce: web3.utils.toHex(txCount),
from: address,
to: ToAddress,
value: web3.utils.toHex(web3.utils.toWei('1', 'ether')),
gasLimit: web3.utils.toHex(21000),
chainId: web3.utils.toHex(97),
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei'))

}
// Sign the transaction
const tx = new Tx(txObject, { chain: 'ropsten' });
tx.sign(privateKey)

const serializedTx = tx.serialize()
const raw = '0x' + serializedTx.toString('hex')

web3.eth.sendSignedTransaction(raw, (err, txHash) => {
console.log('err:', err, 'txHash:', txHash)
})
});

Apr 18, 2022, 11:03 AM
Pas te bin
Apr 18, 2022, 11:04 AM
err: { Error: Returned error: invalid sender
Apr 18, 2022, 11:04 AM

© 2024 Draquery.com All rights reserved.