getDataToSignForPersonalSign,
getBiconomyForwarderConfig
} from './biconomyForwarderHelpers';
let sigUtil = require("eth-sig-util"); // additional dependency
// This web3 instance is used to get user signature from connected wallet
let walletWeb3 = new Web3(window.ethereum);
let userAddress = <selected address>;
let networkId = <your provider networkId here>;
let contract = new web3.eth.Contract(
let functionSignature = contract.methods
let txGas = await contract.methods
.estimateGas({ from: userAddress });
let forwarder = await getBiconomyForwarderConfig(networkId);
let forwarderContract = new web3.eth.Contract(
//const batchId = await forwarderContract.methods.getBatch(userAddress).call();
const batchNonce = await forwarderContract.methods.getNonce(address,0).call();
const gasLimitNum = Number(txGas);
const to = <CONTRACT_ADDRESS>;
const request = await buildForwardTxRequest({account:userAddress,to,gasLimitNum,batchId,batchNonce,data:functionSignature});
/* If you wish to use EIP712 Signature type check below code*/
const hashToSign = getDataToSignForPersonalSign(request);
const sig = await walletWeb3.eth.personal.sign("0x" + hashToSign.toString("hex"), userAddress);
sendTransaction({userAddress, request, sig, signatureType:biconomy.PERSONAL_SIGN});
// notice domain seperator is not passed here
///////////////////////////////////////////////////////////
// If you wish to use EIP712 Signature type
//build the request as mentioned above
const domainSeparator = await getDomainSeperator(42);
console.log(domainSeparator);
const dataToSign = await getDataToSignForEIP712(request,networkId);
walletWeb3.currentProvider.send(
method: "eth_signTypedData_v4",
params: [userAddress, dataToSign]
function (error, response) {
console.info(`User signature is ${response.result}`);
if (error || (response && response.error)) {
showErrorMessage("Could not get user signature");
} else if (response && response.result) {
let sig = response.result;
sendTransaction({userAddress, request, domainSeparator, sig, signatureType:biconomy.EIP712_SIGN});