sendSignedTransaction

Mexa supports signed transactions seamlessly

Create a raw transaction interacting with smart contract functions or just doing the value transfer and send transaction using web3 functionweb3.eth.sendSignedTransaction(data, callback) and forget about paying and setting the transaction fee.

Parameters

data In order to avoid any replay attacks, user needs to provide a signature, message that was signed and raw transaction in json object as first parameter.

callback Optional callback, returns an error object as first parameter and the result as second.

Returns

Promise Promise that resolves to transaction receipt once the transaction is confirmed.

Example Code

let address = <wallet public address>;
let privateKey = <0x address private key>;
let txParams = {
"from": address,
"gasLimit": web3js.utils.toHex(210000),
"to": contractAddress,
"value": "0x0",
"data": contract.methods.addRating(1, 5).encodeABI()
};
const signedTx = await web3.eth.accounts.signTransaction(txParams, `${privateKey}`);
const message = await biconomy.getUserMessageToSign(address);
const sign = await web3.eth.accounts.sign(message, `${privateKey}`);
let rawTransaction = signedTx.rawTransaction;
let data = {
message: message,
signature: sign.signature,
rawTransaction: rawTransaction
};
let receipt = await web3.eth.sendSignedTransaction(data, (error, txHash)=>{
if(error) {
return console.error(error);
}
console.log(txHash);
});