Skip to content

Instantly share code, notes, and snippets.

@carlosgj94
Created May 2, 2022 16:34
Show Gist options
  • Save carlosgj94/f1c4070588492c9f5ad1c6997b5c8c02 to your computer and use it in GitHub Desktop.
Save carlosgj94/f1c4070588492c9f5ad1c6997b5c8c02 to your computer and use it in GitHub Desktop.
const ethers = require('ethers');
async function main() {
let privatekey = '<<PRIVATE_KEY>>'; // Yeah this should be done through an env var, I know but this is a f gist
let wallet = new ethers.Wallet(privatekey);
console.log('Using wallet address ' + wallet.address);
let transaction = {
to: '0xc1fd1272fA7B402FfE445e890F888247d66d8F9F',
value: ethers.utils.parseEther('0.001'),
gasLimit: '21000',
maxPriorityFeePerGas: ethers.utils.parseUnits('5', 'gwei'),
maxFeePerGas: ethers.utils.parseUnits('90', 'gwei'),
nonce: 227,
type: 2,
chainId: 1
};
// sign and serialize the transaction
let rawTransaction = await wallet.signTransaction(transaction).then(ethers.utils.serializeTransaction(transaction));
// print the raw transaction hash
console.log('Raw txhash string ' + rawTransaction);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment