Overview
A complete Newton integration involves five steps:Prerequisites
| Requirement | Use |
|---|---|
| Rust + Cargo | Building and running newton-cli |
| Node.js >= 20 + npm | Running @bytecodealliance/jco and the Next.js app |
Foundry (forge, cast, anvil) | Compiling and deploying Solidity contracts |
| newton-cli 0.2.0 | Uploading policy files, generating CIDs, deploying policies |
| Pinata account | IPFS pinning (you will need a JWT and a gateway URL) |
| Sepolia ETH | Gas fees on the Ethereum Sepolia testnet |
| Newton API key | Authenticate SDK requests — create one via the Newton Dashboard API (SIWE or email authentication), or email product@magicnewton.com |
Install tooling
Step 1: Write a Data Oracle
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
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
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
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
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.