Skip to main content
Newton provides simulation endpoints and local tools at every layer of the stack. Use these to validate your policies, oracles, and integration before deploying to production.

Local Policy Simulation

Test Rego policy logic without the network using the Newton CLI:
newton-cli regorus eval \
  --policy policy.rego \
  --input '{"from":"0xAbC...","to":"0xDeF...","value":"0x0","data":"0x","chainId":"0xaa36a7","functionSignature":"0x"}' \
  --data '{"params":{"max_amount":"1000"},"data":{"eth_price_usd":2500}}'
This evaluates your Rego policy locally with full support for Newton crypto extensions (newton.crypto.ecdsa_recover_signer, newton.crypto.ecdsa_recover_signer_personal).

Local Oracle Simulation

Test your WASM data oracle without deploying:
newton-cli --chain-id 11155111 policy-data simulate \
  --wasm-file policy.wasm \
  --input-json '{"address": "0x742d35Cc6634C0532925a3b844Bc9e7595f2bD18"}'
The CLI runs your WASM component in a sandboxed environment with the Newton HTTP host. The --input-json value is passed to your run function as the input string.

Gateway Simulation

Simulate a full policy evaluation via the Gateway RPC without any on-chain interaction:

Simulate a Task

Tests the complete evaluation pipeline (data oracle + policy) for a specific PolicyClient:
curl -X POST https://gateway.testnet.newton.xyz \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your_api_key>" \
  -d '{
    "jsonrpc": "2.0",
    "method": "newt_simulateTask",
    "params": {
      "policy_client": "0xYourPolicyClientAddress",
      "intent": {
        "from": "0xCallerAddress",
        "to": "0xTargetAddress",
        "value": "0x0",
        "data": "0x",
        "chain_id": "0xaa36a7",
        "function_signature": "0x"
      }
    },
    "id": 1
  }'

Simulate Policy Only

Test Rego policy evaluation with provided inputs (no oracle execution):
curl -X POST https://gateway.testnet.newton.xyz \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your_api_key>" \
  -d '{
    "jsonrpc": "2.0",
    "method": "newt_simulatePolicy",
    "params": {
      "policy_cid": "bafyrei...",
      "intent": { ... },
      "data": { "eth_price_usd": 2500 },
      "params": { "max_amount": "1000" }
    },
    "id": 1
  }'

Simulate PolicyData Only

Test a WASM oracle execution via the Gateway:
curl -X POST https://gateway.testnet.newton.xyz \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your_api_key>" \
  -d '{
    "jsonrpc": "2.0",
    "method": "newt_simulatePolicyData",
    "params": {
      "policy_data_cid": "bafyrei...",
      "input": "{\"address\":\"0x...\"}",
      "secrets": { "API_KEY": "sk-test-xxx" }
    },
    "id": 1
  }'

Simulation Endpoints Comparison

Newton provides four distinct simulation endpoints for different phases of policy development:
EndpointPurposeData SourceOperatorsUse Case
newt_simulatePolicyDataTest WASM plugin executionCaller provides secrets directlyYes (delegation)Iterate WASM before uploading secrets
newt_simulatePolicyDataWithClientVerify stored secrets workReads secrets from gateway DBYes (delegation)Verify uploaded secrets
newt_simulatePolicyFull Rego + WASM evaluationDelegates to operators for full pipelineYes (full pipeline)Final testing before deployment
newt_simulateTaskReplay with pre-assembled dataUses provided PolicyTaskData directlyNo (local only)Replay historical tasks, debugging
simulatePolicy delegates to an operator via broadcast_first_success — it runs the full data pipeline (fetches WASM from IPFS, decrypts stored secrets, executes each PolicyData plugin, merges outputs, evaluates Rego). simulateTask takes pre-assembled PolicyTaskData and evaluates Rego against it locally — the data pipeline is skipped because data is already assembled. Recommended development workflow:
  1. Deploy PolicyData contracts
  2. Test WASM locally with newt_simulatePolicyData
  3. Upload secrets via newt_storeEncryptedSecrets
  4. Verify stored secrets with newt_simulatePolicyDataWithClient
  5. Test full policy end-to-end with newt_simulatePolicy
  6. Deploy Policy on-chain
  7. Submit production tasks with newt_createTask / newt_sendTask
  8. Debug/replay tasks with newt_simulateTask

Newton Explorer

The Newton Explorer provides a visual interface for inspecting tasks, attestations, and policy evaluations on-chain. Use it to:
  • View task status and results
  • Inspect attestation details (signers, quorum, expiration)
  • Trace the evaluation flow from intent to on-chain verification

BLS Diagnostics

If an attestation fails on-chain verification, check:
CheckHow
Attestation expirationCompare attestation.expiration against current block number
Signer bitmapVerify the signer bitmap includes enough operators for quorum
Reference blockEnsure the reference block matches the operator set used for verification
Chain IDConfirm the intent’s chainId matches the chain where the PolicyClient is deployed

Debugging Patterns

SymptomLikely CauseDiagnostic Step
newt_simulateTask returns non-compliantPolicy logic rejects the intentRun newt_simulatePolicy with the same inputs to isolate the Rego evaluation
Oracle returns empty dataWASM run function error or HTTP fetch failureTest locally with newton-cli policy-data simulate
Attestation expires before on-chain submissionToo much time between evaluation and transactionReduce latency or increase the expiry_offset parameter
On-chain verification failsOperator set rotated or wrong chainCheck reference block and chain ID
TaskAlreadyExists errorDuplicate intent hashModify the intent nonce or wait for the existing task
Policy returns CAP instead of ALLOWIntent value exceeds policy thresholdCheck data.params values on your PolicyClient

SDK Debugging

Enable verbose logging in the Newton SDK:
import { createPublicClient, http } from 'viem';
import { sepolia } from 'viem/chains';
import { newtonPublicClientActions } from '@magicnewton/newton-protocol-sdk';

const client = createPublicClient({
  chain: sepolia,
  transport: http(),
}).extend(newtonPublicClientActions({
  apiKey: process.env.NEWTON_API_KEY!,
  gatewayUrl: 'https://gateway.testnet.newton.xyz',
}));

// Simulate first to debug
const simulation = await client.simulateTask({
  policyClient: '0xYourPolicyClientAddress',
  intent: { /* ... */ },
});

console.log('Simulation result:', JSON.stringify(simulation, null, 2));

Next Steps

Deployment Checklist

Pre-launch verification checklist

Error Reference

Complete error code reference