import{s as c,F as y,x as u,r as f,G as m,f as i,H as g,Z as l}from"./thirdweb-Co3M1EyP.js";const d=0n;async function x({account:a,serializableTransaction:e,transaction:s,gasless:n}){const r=u({address:n.relayerForwarderAddress,chain:s.chain,client:s.client}),o=await f({contract:r,method:"function getNonce(address,uint256) view returns (uint256)",params:[a.address,d]}),h=Math.floor(Date.now()/1e3)+(n.deadlineSeconds??3600),t={batchId:d,batchNonce:o,data:e.data,deadline:h,from:a.address,to:e.to,token:l,tokenGasPrice:0n,txGas:e.gas};if(!t.to)throw new Error("Cannot send a transaction without a `to` address");if(!t.txGas)throw new Error("Cannot send a transaction without a `gas` value");if(!t.data)throw new Error("Cannot send a transaction without a `data` value");const w=m([{type:"address"},{type:"address"},{type:"address"},{type:"uint256"},{type:"uint256"},{type:"uint256"},{type:"uint256"},{type:"bytes32"}],[i(t.from),i(t.to),i(t.token),t.txGas,t.tokenGasPrice,t.batchId,t.batchNonce,g(t.data)]),p=await a.signMessage({message:w});return[t,p]}async function C(a){const[e,s]=await x(a),n=await fetch("https://api.biconomy.io/api/v2/meta-tx/native",{body:c({apiId:a.gasless.apiId,from:e.from,gasLimit:e.txGas,params:[e,s],to:e.to}),headers:{"Content-Type":"application/json;charset=utf-8","x-api-key":a.gasless.apiKey},method:"POST"});if(!n.ok)throw new Error(`Failed to send transaction: ${await n.text()}`);const r=await n.json(),o=r.txHash;if(y(o))return{chain:a.transaction.chain,client:a.transaction.client,transactionHash:o};throw new Error(`Failed to send transaction: ${c(r)}`)}export{x as prepareBiconomyTransaction,C as relayBiconomyTransaction};
