Skip to main content
This guide walks through the core Shield workflow: simulate a transaction to predict its outcome, then validate it before signing. We’ll use a simple ETH → WETH wrap as the example transaction — the calldata is just 0xd0e30db0 (the deposit() function selector), so you can copy-paste and run immediately.

Prerequisites

1. Simulate a Transaction

Send your transaction to the simulate endpoint to get predicted output amounts and gas consumption.
curl -X POST https://shield.api.enso.build/api/v1/simulate \
  -H "Authorization: Bearer $ENSO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "chainId": 1,
    "transaction": {
      "data": "0xd0e30db0",
      "value": "1000000000000000000",
      "to": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
      "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
    },
    "tokenIn": ["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"],
    "tokenOut": ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"],
    "amountIn": ["1000000000000000000"]
  }'
Response:
{
  "simulationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "chainId": 1,
  "result": {
    "status": "Success",
    "amountOut": ["1000000000000000000"],
    "gas": "46000"
  }
}
The simulationId is a UUID you’ll use in the next step to validate the transaction before signing.

2. Validate Before Signing

Before signing the transaction, send it with the simulationId to confirm nothing has changed.
curl -X POST https://shield.api.enso.build/api/v1/validate \
  -H "Authorization: Bearer $ENSO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "simulationId": "<SIMULATION_ID>",
    "transaction": {
      "data": "0xd0e30db0",
      "to": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
      "from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
      "value": "1000000000000000000",
      "chainId": 1
    }
  }'
Response:
{
  "valid": true,
  "simulationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "checks": {
    "chainId": true,
    "data": true,
    "to": true,
    "value": true,
    "from": true
  }
}

3. Sign and Submit

Once validated, sign and submit the transaction using any web3 library.
import { createWalletClient, http } from "viem";
import { mainnet } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount("0x...");
const client = createWalletClient({ account, chain: mainnet, transport: http() });

if (validation.valid) {
  const hash = await client.sendTransaction({
    to: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
    data: "0xd0e30db0",
    value: BigInt("1000000000000000000"),
  });
  console.log("Transaction hash:", hash);
}
Simulations are cached for 5 minutes. Validate within this window, or re-simulate to get a fresh simulationId.
Shield works with transactions from any source — Uniswap, Enso, Aave, or your own contracts. See the Third-Party Transactions guide for examples.

Updated