Prerequisites
- A deployed PolicyClient contract (see Smart Contract Integration)
- A Newton API key (see Getting an API Key)
- Node.js >= 20
Step 1: Create the Project
Step 2: Environment Variables
Create.env.local:
NEXT_PUBLIC_POLICY_CONTRACT_ADDRESS is the Newton Policy contract (fixed on Sepolia). NEXT_PUBLIC_POLICY_WALLET_ADDRESS is YOUR deployed PolicyClient. These are different contracts.Step 3: Create Configuration
Createsrc/const/config.ts:
Step 4: Create the Newton Client
Createsrc/lib/use-newton-client.ts:
Step 5: Submit an Evaluation Request
Createsrc/lib/evaluation-request.ts:
Step 6: Execute an Attested Transaction
UseevaluateIntentDirect to get an attestation, then submit the attested transaction on-chain:
Gateway Response Handling
When working with the gateway directly (outside the SDK), be aware of these serialization details.Field Name Mapping
The gateway uses different casing fortask (camelCase) and task_response (snake_case):
Byte Array Conversion
The gateway returns all Soliditybytes fields as JSON number arrays ([0,0,...,0,1]), not hex strings. Viem expects hex strings and fails with x.replace is not a function if given arrays.
toHex() to these fields before ABI encoding: evaluationResult, intentSignature, wasmArgs, quorumNumbers, policy, policyData[].data, policyData[].attestation, policyConfig.policyParams, taskId, and policyId.
Decoding evaluationResult
evaluationResult is an ABI-encoded boolean (32 bytes). The gateway returns it as a JSON byte array:
status: "success" in the gateway response means BLS aggregation completed, not that the policy approved the intent. Operators sign the evaluation result regardless of allow/deny. The actual policy decision is in evaluationResult.Function Signature Encoding
Step 7: Run the Application
Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
GATEWAY_ERROR | Invalid API key or network issue | Verify NEWTON_API_KEY and network connectivity |
InvalidAttestation on-chain | Task Manager mismatch or expired attestation | Verify contract was initialized with correct Task Manager address |
| WebSocket connection failed | Wrong WS URL or Alchemy plan limits | Verify SEPOLIA_ALCHEMY_WS_URL format (wss://...) |
TIMEOUT | Operator network slow or unavailable | Increase timeout or retry |
Next Steps
SDK Reference
Full TypeScript SDK documentation
RPC API
Underlying JSON-RPC methods