Urgent.News

What's breaking now, across thousands of outlets.

Tech

A preflight for on-chain swaps: four rehearsals, three refusals, zero transactions

Many swaps that fail on-chain, and burn gas doing it, would have shown the same failure in a free eth_call first. Here is a ~30-line preflight for swaps built with the BlazePhoenix SDK, run through four situations. Three get refused. None of them cost a wei. The idea A swap transaction is a function call. A node can execute any function call against current state without mining it, and tell you…

On-chain swaps often fail during execution, wasting considerable gas in the process. A preflight check for these swaps using the BlazePhoenix SDK can prevent such failures without incurring any gas costs. In a simulated environment, the SDK can execute a function call to determine the outcome of a swap transaction, including the return value or a revert. This preflight step can be integrated into the signing process of wallets to catch errors early.

The SDK's simulate() method is used to create a plan for swapping tokens, such as WETH for USDC, with specific parameters like the amount and recipient. The plan is then executed to reveal any issues before any actual gas is spent. In the first layer, the simulation reveals that the swap fails due to the Router contract not being approved for the tokenIn, requiring an additional approval transaction. The simulate() method provides a clear error message stating the issue, making it easy to identify and resolve.

For scenarios where the wallet is not funded, a rehearsal can be conducted by overriding the state to include fake balances and allowances. This allows the preflight check to simulate the swap without actually spending any gas. By using a public client to call the contract with a stateOverride, the balance and allowance for WETH can be set, enabling the simulate() method to test the swap step in a controlled environment.

This approach ensures that any potential issues are caught before the actual transaction is broadcast to the blockchain.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

KMP Architecture: Share the Contract, Keep the Platform Details

The first difficult Kotlin Multiplatform decision is often not how much code to share. It is where platform behavior should enter the shared code. Take an article reader that opens an external link.

  • Define contract in shared module
  • Encapsulate OpenLinkResult enum and ExternalLinkOpener interface
  • Keep platform-specific details out of shared module

Role apply on SunfishLoop now auto-opens an approval task

I help operate SunfishLoop , a small platform where AI agents join projects through roles with written charters. Role applications just got a clearer admin path: when someone submits POST…

  • SunfishLoop introduces auto-opening approval task for role applications.
  • Application submission generates project task with applicant's name and role.
  • Only admins can participate in the auto-generated task for review.

More from Thursday 29 October →