🛡️ Safety & Pre-Execution Checks

🔐 1. Confirmation Gate

Before calling any write function (deploy(), transfer(), mint(), etc.), Dialect AI:

  • Displays a summary of the action:

    • Contract type

    • Parameters (e.g., token name, supply)

    • Recipient address

    • Estimated gas cost

  • Prompts the user:

    “Do you want to proceed with this transaction?”

  • Waits for explicit confirmation (via frontend UI or chat message)

🧠 Example:

“You're about to send 200 MYT to 0xabc.... Estimated gas: 0.002 ETH. Please confirm to proceed.”


🔑 2. Wallet Availability Check

  • Verifies that the user has a connected wallet

  • Retrieves their address, signer, and chain ID

  • Fails gracefully if wallet is missing or disconnected

If the user is not connected:

❗ “No wallet detected. Please connect MetaMask to continue.”


⛽ 3. Gas Estimation

Dialect AI automatically performs a dry-run gas estimation using:

tsCopyEditcontract.estimateGas.functionName(...args)

This allows the bot to:

  • Predict the cost of the transaction in gas units

  • Convert to ETH using provider.getGasPrice()

  • Warn the user if the cost exceeds a threshold (e.g., gas spike)

🧠 Example:

“This transaction will likely cost ~0.0013 ETH in gas. Proceed?”


🧪 4. Dry Run / Static Call (If Possible)

Where supported, Dialect AI attempts to simulate the transaction without sending it to the network using callStatic:

tsCopyEditconst result = await contract.callStatic.functionName(...args);

Use cases:

  • Checking if a token transfer would revert (e.g., insufficient balance)

  • Verifying mint success before committing gas

  • Ensuring the deployer has enough ETH to cover deployment

Dry run failures result in:

❌ “This transaction would fail: Revert - insufficient funds.”


🔁 5. Nonce & Duplicate Prevention

Dialect AI prevents double submissions by:

  • Tracking pending transactions in memory (txPool)

  • Locking intent execution until the previous transaction is confirmed or rejected

  • Warning the user about duplicate actions (e.g., sending the same token twice)

🧠 Example:

“You already have a pending transfer of 50 MYT to this address. Wait until it's confirmed before retrying.”


🚨 6. Fallbacks for Failed Transactions

If a transaction fails:

  • The bot detects revert reasons (e.g., gas limit exceeded, failed require)

  • Parses the error via try/catch from ethers.js

  • Returns a helpful explanation to the user

Example:

tsCopyEdittry {
  await contract.transfer(recipient, amount);
} catch (err) {
  if (err.code === "INSUFFICIENT_FUNDS") {
    reply("Transaction failed: You don’t have enough ETH to cover gas.");
  }
}

Last updated