- Use an existing policy
- Build everything from scratch
If a policy is already deployed (e.g., you completed the quickstart or someone shared a policy address with you), skip directly to Step 4: Smart Contract Integration or Step 5: Frontend SDK Integration. You only need Node.js and optionally Foundry.
Overview
A complete Newton integration involves five steps:Steps 4 and 5 (dashed) can be done independently if you already have a deployed policy. You do not need the full toolchain to integrate via the SDK.
Prerequisites
Install only what you need for the steps you plan to follow:| Requirement | Steps | Use |
|---|---|---|
| Node.js >= 20 + npm | All | SDK, frontend, WASM tooling |
| Sepolia ETH | 3–5 | Gas fees on testnet |
| Newton API key | 4–5 | Authenticate SDK requests — create one here |
Foundry (forge, cast, anvil) | 4 | Compiling and deploying Solidity contracts |
| Rust + Cargo | 1–3 | Building and running newton-cli |
| newton-cli 0.1.35 | 3 | Uploading policy files, generating CIDs, deploying policies |
| Pinata account | 3 | IPFS pinning (you will need a JWT and a gateway URL) |
Install all tooling (Steps 1–5)
Install all tooling (Steps 1–5)
Step 1: Write a Data Oracle (~30 min)
Build a WebAssembly component that fetches external data (e.g., price feeds, sanctions screening, KYC status) for policy evaluation.Writing Data Oracles
Define the WIT interface, implement in JavaScript, build WASM, test locally
Step 2: Write a Rego Policy (~20 min)
Create a Rego policy that evaluates transaction intents using data from your oracle and configuration parameters.Writing Policies
Write Rego rules, define parameter schemas, organize policy files
Step 3: Deploy with CLI (~15 min)
Upload your policy files to IPFS and register PolicyData and Policy contracts on-chain.Deploying with CLI
Generate CIDs, deploy PolicyData, deploy Policy, register PolicyClient
Step 4: Smart Contract Integration (~30 min)
Deploy a PolicyClient smart contract that validates Newton attestations before executing transactions.Smart Contract Integration
Inherit NewtonPolicyClient, configure validation, deploy with Foundry
Step 5: Frontend SDK Integration (~30 min)
Build a Next.js application that submits evaluation requests via the SDK and executes attested transactions.Frontend SDK Integration
Create Newton client, submit evaluations, execute with attestations
End-to-End Flow
Once everything is deployed:- Your frontend submits an Intent via the Newton SDK
- The Newton Gateway forwards it to AVS operators
- Operators run the WASM data oracle, evaluate the Rego policy, and produce BLS-signed attestations
- The attestation is returned to your app
- Your app submits the transaction + attestation to the PolicyClient on-chain
- The contract validates the attestation and executes the transaction
Troubleshooting
'command not found' after installing tools
'command not found' after installing tools
Restart your shell after installing Rust, Node via Homebrew, or Foundry:
jco componentize fails
jco componentize fails
Ensure both packages are installed:If installed locally, use
npx jco componentize ....InvalidAttestation error (0xbd8ba84d)
InvalidAttestation error (0xbd8ba84d)
Most common cause: wrong Task Manager address. The wallet must use
0xecb741F4875770f9A5F060cb30F6c9eb5966eD13 on Sepolia. BLS signatures are bound to this address.Other causes: intent parameter mismatch, policy ID mismatch, incorrect struct passthrough from evaluateIntentDirect.ExecutionFailed error (0xacfdb444)
ExecutionFailed error (0xacfdb444)
The attestation passed but the inner call reverted. Common causes:
- Wallet contract has no ETH (fund it directly)
- Target contract reverted
- Malformed calldata
WebSocket connection fails
WebSocket connection fails
Use
wss:// protocol, not https://:Policy evaluation times out
Policy evaluation times out
- Test WASM locally with
newton-cli policy-data simulate - Verify
wasmArgsformat matches your WASM expectations - Increase the
timeoutvalue in the evaluation request - Check external APIs your WASM calls are responding
Factory Pattern
Advanced: Factory pattern for deploying multiple PolicyClients
Advanced: Factory pattern for deploying multiple PolicyClients
If you need to deploy multiple PolicyClient instances (e.g., one per user), use a factory contract:This deploys pre-configured wallet instances bound to your policy. Each user gets their own wallet with the same policy enforcement.
Have questions?
Get in touch with someone from the Newton team to discuss your integration