Skip to main content
This guide walks through the full Newton Protocol integration flow. Each step links to a dedicated guide with complete code and instructions.

Overview

A complete Newton integration involves five steps:

Prerequisites

RequirementUse
Rust + CargoBuilding and running newton-cli
Node.js >= 20 + npmRunning @bytecodealliance/jco and the Next.js app
Foundry (forge, cast, anvil)Compiling and deploying Solidity contracts
newton-cli 0.2.0Uploading policy files, generating CIDs, deploying policies
Pinata accountIPFS pinning (you will need a JWT and a gateway URL)
Sepolia ETHGas fees on the Ethereum Sepolia testnet
Newton API keyAuthenticate SDK requests — create one via the Newton Dashboard API (SIWE or email authentication), or email product@magicnewton.com

Install tooling

# 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.2.0

# 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

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:
  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

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.