Skip to main content
This guide walks through the full Newton Protocol integration: a WASM data oracle, a Rego policy, a PolicyClient smart contract, and a frontend that submits intents and executes attested transactions. Choose your starting point based on what you need:
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:
RequirementStepsUse
Node.js >= 20 + npmAllSDK, frontend, WASM tooling
Sepolia ETH3–5Gas fees on testnet
Newton API key4–5Authenticate SDK requests — create one here
Foundry (forge, cast, anvil)4Compiling and deploying Solidity contracts
Rust + Cargo1–3Building and running newton-cli
newton-cli 0.1.353Uploading policy files, generating CIDs, deploying policies
Pinata account3IPFS pinning (you will need a JWT and a gateway URL)
# Rust (includes cargo)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Node.js (macOS — or use your preferred method)
brew install node

# Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup

# newton-cli
cargo install newton-cli@0.1.35

# jco (WASM componentization)
npm install -g @bytecodealliance/jco @bytecodealliance/componentize-js
After installing Rust, Foundry, or Node via Homebrew, restart your terminal (or run source ~/.zshrc) so the new binaries are on your PATH.

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:
  1. Your frontend submits an Intent via the Newton SDK
  2. The Newton Gateway forwards it to AVS operators
  3. Operators run the WASM data oracle, evaluate the Rego policy, and produce BLS-signed attestations
  4. The attestation is returned to your app
  5. Your app submits the transaction + attestation to the PolicyClient on-chain
  6. The contract validates the attestation and executes the transaction
For the full architecture, see Architecture.

Troubleshooting

Restart your shell after installing Rust, Node via Homebrew, or Foundry:
source ~/.zshrc  # or source ~/.bashrc
Ensure both packages are installed:
npm install -g @bytecodealliance/jco @bytecodealliance/componentize-js
If installed locally, use npx jco componentize ....
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.
The attestation passed but the inner call reverted. Common causes:
  • Wallet contract has no ETH (fund it directly)
  • Target contract reverted
  • Malformed calldata
Use wss:// protocol, not https://:
NEXT_PUBLIC_SEPOLIA_ALCHEMY_WS_URL=wss://eth-sepolia.g.alchemy.com/v2/YOUR_KEY
  • Test WASM locally with newton-cli policy-data simulate
  • Verify wasmArgs format matches your WASM expectations
  • Increase the timeout value in the evaluation request
  • Check external APIs your WASM calls are responding

Factory Pattern

If you need to deploy multiple PolicyClient instances (e.g., one per user), use a factory contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import {NewtonPolicyWallet} from "./NewtonPolicyWallet.sol";

contract WalletFactory {
    address public immutable taskManager;
    address public immutable policy;

    event WalletCreated(address indexed owner, address wallet);

    constructor(address _taskManager, address _policy) {
        taskManager = _taskManager;
        policy = _policy;
    }

    function createWallet() external returns (address) {
        NewtonPolicyWallet wallet = new NewtonPolicyWallet();
        wallet.initialize(taskManager, policy, msg.sender);
        emit WalletCreated(msg.sender, address(wallet));
        return address(wallet);
    }
}
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