Created
March 4, 2021 13:34
-
-
Save WP-LKL/2a5fc1c695ff39f10a79b4149c1a1f60 to your computer and use it in GitHub Desktop.
Binance Smart Chain transaction using web3 and ethereumjs with custom chain and commandline for python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ex. $ npx ts-node BscRawTx.ts --txData=<txData> | |
// Consult: https://github.com/WP-LKL/bscValueDefi-Exploit, for python use-case | |
const Tx = require('ethereumjs-tx').Transaction; | |
const Web3 = require('web3'); | |
import Common from 'ethereumjs-common'; | |
import {parse} from 'ts-command-line-args'; | |
interface input { | |
txData: string; | |
} | |
export const inputs = parse<input>({ | |
txData: { | |
type: String, | |
optional: true, | |
} | |
}) | |
console.log(inputs["txData"]) | |
const web3 = new Web3("https://bsc-dataseed.binance.org"); | |
const privKey = Buffer.from("SECRETKEY", 'hex'); | |
const addressFrom = "0xMYADDRESS"; | |
const addressTo = '0xRECEPIENT/CONTRACT_ADDRESS'; | |
web3.eth.getTransactionCount(addressFrom, (err, txCount) => { | |
const common = Common.forCustomChain('mainnet', { | |
name: 'bnb', | |
networkId: 56, | |
chainId: 56 | |
}, 'petersburg'); | |
const txObject = { | |
nonce: web3.utils.toHex(txCount), | |
to: addressTo, | |
value: web3.utils.toHex(web3.utils.toWei('0.0', 'ether')), | |
gasLimit: web3.utils.toHex(700000), | |
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')), | |
data: inputs["txData"], | |
}; | |
const tx = new Tx(txObject, {common}); | |
tx.sign(privKey); | |
const serializedTrans = tx.serialize(); | |
const raw = '0x' + serializedTrans.toString('hex'); | |
web3.eth.sendSignedTransaction(raw, (err, txHash) => { | |
console.log('txHash:', txHash) | |
}); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment