Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
encode Rinkeby DAI sendSignedTransaction
const receiverAddress = "<Rinkeby receiver address>"
const senderAddress = "<Rinkeby sender address>";
const privKey = "<sender private key>"; // do not disclose the private key
function sendSignedTx(transactionObject, cb) {
let transaction = new EthTx(transactionObject);
const privateKey = new Buffer.from(privKey, "hex");
transaction.sign(privateKey); // sign a transaction
const serializedEthTx = transaction.serialize().toString("hex"); // serialize the transaction
web3.eth.sendSignedTransaction(`0x${serializedEthTx}`, cb); // send signed transaction
web3.eth.getTransactionCount(senderAddress).then(async (transactionNonce) => {
const transactionObject = {
chainId: 4,
nonce: web3.utils.toHex(transactionNonce),
gasLimit: web3.utils.toHex(500000),
gasPrice: web3.utils.toHex(10000000000),
value: 0,
to: daiExchangeAddress,
from: senderAddress,
data: exchangeEncodeABI
sendSignedTx(transactionObject, (err, ret) => {
if (err) {
console.log("An error occurred", err)
console.log("The txHash is: ", ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment