sendSignedTransaction

Mexa supports signed transactions seamlessly

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

Parameters

rawTransaction Signed transaction data in HEX format

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

Returns

PromiEvent A promise combined event emitter. Will be resolved when the transaction receipt is available.

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

Biconomy Contract Wallet is not in active development. If you want to use a proxy contract on mainnet then it is recommended to use Gnosis or Argent proxy contract as we support external smart contract wallets also. Read more about it here

In this approach, you need to pass extra information along with rawTransaction signed by user's private key. Same web3 method web3.eth.sendSignedTransaction(data, callback) will be used here but with different parameters mentioned below

Note: Make sure you are already logged into biconomy before sending the transactions.

Parameters

data JSON Object containing user signature and the raw transaction. Data to be signed can be get using method getUserMessageToSign(rawTransaction) provided by Mexa SDK.

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

Returns

PromiEvent A promise combined event emitter. Will be resolved when the transaction receipt is available.

Example Code

// Import sigUtil for signing data
var sigUtil = require('eth-sig-util')
let address = <wallet public address>;
let privateKey = <private key>;
let txParams = {
"from": address,
"gasLimit": web3.utils.toHex(210000),
"to": contractAddress,
"value": "0x0",
"data": contract.methods.addRating(1, 5).encodeABI()
};
const signedTx = await web3.eth.accounts.signTransaction(txParams, `0x${privateKey}`);
const dataToSign = await biconomy.getUserMessageToSign(signedTx.rawTransaction);
const signature = sigUtil.signTypedMessage(new Buffer.from(privateKey, 'hex'),
{data: dataToSign}, 'V3');
let rawTransaction = signedTx.rawTransaction;
let data = {
signature: signature,
rawTransaction: rawTransaction
};
// Use any one of the methods below to check for transaction confirmation
// USING PROMISE
let receipt = await web3.eth.sendSignedTransaction(data, (error, txHash)=>{
if(error) {
return console.error(error);
}
console.log(txHash);
});
/********* OR *********/
// Get the transaction Hash using the Event Emitter returned
web3.eth.sendSignedTransaction(data)
.on('transactionHash', (hash)=> {
console.log(`Transaction hash is ${hash}`)
})
.once('confirmation', (confirmation, receipt)=> {
console.log(`Transaction Confirmed.`);
console.log(receipt);
});