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 JSON Object container user signature, message that was signed and the raw transaction. Message that is signed must include a user specific nonce in order to prevent replay attacks.

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);
});

In this approach there is no change in the way you call web3.js sendSignedTransaction method. Mexa will handle the transaction and relay them to Biconomy server and then to blockchain, singed by biconomy relayers.

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}`);
let receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction, (error, txHash)=>{
if(error) {
return console.error(error);
}
console.log(txHash);
});