Skip to main content
These are helper methods used to retrieve information about policies, current task evaluation status, attestations, and more.

Read methods

Setup

The Newton protocol integrates with viem. Install and import the Newton SDK, then extend a PublicClient.
Note: Many policy-related SDK methods accept an optional policyContractAddress. Pass it to scope reads to a specific policy.
import { createPublicClient, webSocket } from 'viem'
import { newtonPublicClientActions } from 'newton-policy-sdk'

const newtonPublicClient = createPublicClient({
  chain: network,
  transport: webSocket(alchemyRpcWSUrls[network.id]),
}).extend(
  newtonPublicClientActions({
    // optional: scope reads to a specific policy contract
    policyContractAddress: undefined, // type: Address | undefined
  })
)

// Example: call a read method
await newtonPublicClient.policyUri()

Policy

getPolicyCid

Signature
getPolicyCid(): Promise<string>
Returns the content ID (CID) of the policy. Example
await newtonPublicClient.getPolicyCid()

getMetadataCid

Signature
getMetadataCid(): Promise<string>
Returns the content ID (CID) of the policy metadata. Example
await newtonPublicClient.getMetadataCid()

supportsInterface

Signature
supportsInterface(params: { interfaceId: `0x${string}` }): Promise<boolean>
Checks if the policy contract supports a specific ERC-165 interface. Example
await newtonPublicClient.supportsInterface({ interfaceId: '0x01ffc9a7' })

owner

Signature
owner(): Promise<Address>
Returns the owner of the policy contract. Example
await newtonPublicClient.owner()

factory

Signature
factory(): Promise<Address>
Returns the factory contract that deployed the policy. Example
await newtonPublicClient.factory()

entrypoint

Signature
entrypoint(): Promise<string>
Gets the entrypoint address for the policy. Example
await newtonPublicClient.entrypoint()

getSchemaCid

Signature
getSchemaCid(): Promise<string>
Returns the CID of the schema definition for this policy. Example
await newtonPublicClient.getSchemaCid()

policyData

Signature
policyData(params: { index: number }): Promise<Address>
Fetches the policy data at a specific index. Example
await newtonPublicClient.policyData({ index: 0 })

clientToPolicyId

Signature
clientToPolicyId(params: { client: Address }): Promise<`0x${string}`>
Maps a client address to its policy ID. Example
await newtonPublicClient.clientToPolicyId({ client: '0xabc123...' })

getPolicyId

Signature
getPolicyId(params: { client: Address }): Promise<`0x${string}`>
Gets the active policy ID for a given client. Example
await newtonPublicClient.getPolicyId({ client: '0xabc123...' })

getPolicyConfig

Signature
getPolicyConfig(params: { policyId: `0x${string}` }): Promise<{
  policyParams: object | string
  policyParamsHex: `0x${string}`
  expireAfter: number
}>
Retrieves user-defined parameters for a given policy ID. Example
await newtonPublicClient.getPolicyConfig({
  policyId: '0xd5fef713ca5afb9dccd36f6e35911cc3360bc3b31174189be989e2f79d152ee5',
})

precomputePolicyId

Signature
precomputePolicyId(params: {
  policyContract: Address
  policyData: Address[]
  params: any
  client: Address
  policyUri: string
  schemaUri: string
  entrypoint: string
  expireAfter?: number
  blockTimestamp?: bigint
}): Promise<`0x${string}`>
SDK utility that precomputes a policy ID locally (no on-chain call). Example
await newtonPublicClient.precomputePolicyId({
  policyContract: '0x123...',
  policyData: ['0x456...', '0x789...'],
  params: { maxUsers: 100 },
  client: '0xabc...',
  policyUri: 'ipfs://QmPolicyCode...',
  schemaUri: 'ipfs://QmSchema...',
  entrypoint: '0xEntrypoint...',
})

Tasks

waitForTaskResponded

Signature
waitForTaskResponded(params: {
  taskId: `0x${string}`
  timeoutMs?: number
  abortSignal?: AbortSignal
}): Promise<TaskResponseResult>
Gets the attestation for a particular task. Critical to complete a verified transaction. Example
await newtonPublicClient.waitForTaskResponded({
  taskId: '0x59fbb0d8aa56b2ecc9047bc91f74f893872b069b75f0186a061d1f6e8420b15b',
  timeoutMs: 10_000,
})

getTaskStatus

Signature
getTaskStatus(params: {
  taskId: `0x${string}`
}): Promise<'Pending' | 'Responded' | 'Expired'>
Checks whether a task is evaluated or pending. Example
await newtonPublicClient.getTaskStatus({
  taskId: '0x59fbb0d8aa56b2ecc9047bc91f74f893872b069b75f0186a061d1f6e8420b15b',
})

getTaskResponseHash

Signature
getTaskResponseHash(params: {
  taskId: `0x${string}`
}): Promise<`0x${string}` | null>
Gets the protocol-specific hash for a task’s response. Example
await newtonPublicClient.getTaskResponseHash({
  taskId: '0x59fbb0d8aa56b2ecc9047bc91f74f893872b069b75f0186a061d1f6e8420b15b',
})

Write methods

Setup

Extend a WalletClient with Newton wallet actions.
Note: policyContractAddress is optional overall, but required for policy write functions.
import { createWalletClient, webSocket } from 'viem'
import { newtonWalletClientActions } from 'newton-policy-sdk'

const signer = /* e.g., Wagmi account */ undefined

const newtonWalletClient = createWalletClient({
  chain: network,
  account: signer,
  transport: webSocket(alchemyRpcWSUrls[network.id]),
}).extend(
  newtonWalletClientActions({
    // required if calling policy write methods
    policyContractAddress: '0x...',
  })
)

Tasks

submitEvaluationRequest

Signature
submitEvaluationRequest(params: {
  policyClient: Address
  intent: {
    from: Address
    to: Address
    value: `0x${string}` | bigint
    data: `0x${string}`
    chainId: `0x${string}` | number | bigint
    functionSignature: `0x${string}`
  }
  quorumNumber?: `0x${string}`
  quorumThresholdPercentage?: number
  wasmArgs?: `0x${string}`
  timeout: number // seconds
}): Promise<`0x${string}`> // tx hash
Submits a new evaluation request against a given policy. Example
await newtonWalletClient.submitEvaluationRequest({
  policyClient: '0x1234567890abcdef1234567890abcdef12345678',
  intent: {
    from: '0x1111111111111111111111111111111111111111',
    to: '0x2222222222222222222222222222222222222222',
    value: 1_000000000000000000n, // 1 ETH
    data: '0xa9059cbb00000000000000000000000033333333333333333333333333333333333333330000000000000000000000000000000000000000000000000000000000000064',
    chainId: 1,
    functionSignature: '0x62757928616464726573732c75696e743235362c75696e74333229',
  },
  quorumNumber: '0x01',
  quorumThresholdPercentage: 67,
  wasmArgs: '0xdeadbeef',
  timeout: 3600, // 1 hour
})
Notes / Risks
  • Choose timeout carefully (too short → failures; too long → locks resources).
  • intent must match the evaluator’s expected schema.
  • Providing both quorumNumber and quorumThresholdPercentage overrides policy defaults.
  • wasmArgs is raw data; ensure correct encoding for the WASM module.

Policy

initialize

Signature
initialize(params: {
  factory: Address
  entrypoint: Address
  policyUri: string
  schemaUri: string
  policyData: Address[]
  owner: Address
}): Promise<`0x${string}`> // tx hash
Initializes the policy contract with its factory, entrypoint, schema, and initial policy data. Call once. Example
await newtonWalletClient.initialize({
  factory: '0x1234567890abcdef...',
  entrypoint: '0xabcdef123456...',
  policyUri: 'ipfs://QmPolicyCode...',
  schemaUri: 'ipfs://QmSchema...',
  policyData: [
    '0x1111111111111111111111111111111111111111',
    '0x2222222222222222222222222222222222222222',
  ],
  owner: '0x1234567890abcdef...',
})
Notes / Risks
  • Call once only; re-initialization may revert or corrupt state.
  • Ensure policyUri and schemaUri are correct and immutable.

renounceOwnership

Signature
renounceOwnership(): Promise<`0x${string}`> // tx hash
Renounces ownership of the policy contract. This action is permanent. Example
await newtonWalletClient.renounceOwnership()
Notes / Risks
  • Permanent; no owner afterward.
  • Owner-restricted functions become unusable.

transferOwnership

Signature
transferOwnership(params: { newOwner: Address }): Promise<`0x${string}`> // tx hash
Transfers ownership of the policy contract to a new address. Example
await newtonWalletClient.transferOwnership({
  newOwner: '0xabcdefabcdefabcdefabcdefabcdefabcdef',
})
Notes / Risks
  • Validate newOwner carefully.
  • If newOwner is a contract, ensure it correctly handles ownership.