Skip to content

Instantly share code, notes, and snippets.

@sunnyRK
Last active January 12, 2024 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnyRK/8e3b8a17099f477b4ce53690d774a176 to your computer and use it in GitHub Desktop.
Save sunnyRK/8e3b8a17099f477b4ce53690d774a176 to your computer and use it in GitHub Desktop.
import { useMutation } from "@tanstack/react-query";
import { iGlobal, useGlobalStore } from "../../store/GlobalStore";
import { iTrading, useTradingStore } from "../../store/TradingStore";
import { ChainIdDetails } from "../../utils/data/network";
import { BigNumber } from "ethers";
import { Bundler, IBundler } from "@biconomy/bundler";
import { DEFAULT_ENTRYPOINT_ADDRESS } from "@biconomy/account";
export function useBiconomyProvider() {
const { smartAccount, selectedNetwork }: iGlobal = useGlobalStore((state) => state);
const { setHasExecutionError }: iTrading = useTradingStore((state) => state);
async function sendToBiconomy(txs) {
try {
const userOp = await smartAccount.buildUserOp(txs);
userOp.paymasterAndData = "0x";
console.log('userOp: ', userOp)
const bundler: IBundler = new Bundler({
bundlerUrl: ChainIdDetails[selectedNetwork.chainId].bundlerURL,
chainId: BigNumber.from(selectedNetwork.chainId).toNumber(),
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
});
const data = await bundler.estimateUserOpGas(userOp)
console.log('data: ', data)
userOp.callGasLimit = data.callGasLimit;
userOp.verificationGasLimit = data.verificationGasLimit;
userOp.maxFeePerGas = data.maxFeePerGas;
userOp.maxPriorityFeePerGas = data.maxPriorityFeePerGas;
userOp.preVerificationGas = data.preVerificationGas;
console.log('userOp-after: ', userOp)
const userOpResponse = await smartAccount.sendUserOp(data);
const txReciept = await userOpResponse.wait();
return txReciept?.receipt.transactionHash;
} catch (error: any) {
console.log("BiconomyError: ", error);
setHasExecutionError(error.message ? error.message : error);
return;
}
}
return useMutation(sendToBiconomy);
}
{
callData: "0x000046800000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000005000000000000000000000000794a61358d6845594f94dc1db02a252b5b4814ad000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da100000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc450000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c31607000000000000000000000000794a61358d6845594f94dc1db02a252b5b4814ad000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000003a00000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000000000000000006469328dec000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000b423cb151695bec59a847780ae7687e18f648a49000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a45ae401dc0000000000000000000000000000000000000000000000000000000065a0feed00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da10000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c316070000000000000000000000000000000000000000000000000000000000000064000000000000000000000000b423cb151695bec59a847780ae7687e18f648a49000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000026db000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000794a61358d6845594f94dc1db02a252b5b4814ad000000000000000000000000000000000000000000000000000000000000270d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084617ba0370000000000000000000000007f5c764cbc14f9669b88837ca1490cca17c31607000000000000000000000000000000000000000000000000000000000000270d000000000000000000000000b423cb151695bec59a847780ae7687e18f648a49000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
callGasLimit: 800000
initCode: "0x"
maxFeePerGas: "4985103"
maxPriorityFeePerGas: "1000000"
nonce: BigNumber {_hex: '0x01', _isBigNumber: true}
paymasterAndData: "0x"
preVerificationGas: 100000
sender: "0xB423Cb151695bEc59A847780Ae7687E18F648A49"
signature: ""
verificationGasLimit: 1000000
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment