❗ Before getting started, ensure that your EOA address is allowlisted with Newton Protocol. Please reach out to [email protected] to learn more.
Deploy a policy template
The first step in using Newton Protocol is deploying a policy template to the protocol.A policy template is a generic policy that can be customized by an end-user with their own parameters. Policy templates consist of a combination of a Rego policy along with a WASM binary for calling data offchain.
Note: This step is optional — you may choose to leverage an existing policy template that’s already deployed.
See this example.
- Write a policy template in Rego. See this guide for what’s supported.
- Use the CLI tool to deploy your policy template:
https://github.com/newt-foundation/developer-policy-cli - At this point, a
policy template addressand IPFS hash will be returned.
Deploy a policy client
The next step in integration is using the policy template as part of a policy client, a Solidity contract. The policy client represents the consumer of the policy proofs — where transactions will be gated by Newton Protocol. Write a Solidity contract to extendNewtonPolicyClient.Initialize for Newton Protocol with the
policy template address you want to use (this can be in the constructor).
Steps:
-
Call
_initNewtonPolicyClient(policyTaskManager, policy, policyClientOwner);fromNewtonPolicyClientin your implementation. -
Update your function to place the policy as a guard.
For example, changetoInside this method, add your business logic. - Deploy the contract.
-
Call
initializewith your policy address and owner.
TheproverTaskManagervalue is0xae08eb5bb2d2debfa248ec6ec0355e6643791a91. -
Call
setParameterswith configuration parameters for the policy (via Etherscan or a client app). Note that this step is mandatory, even if the policy doesn’t require any parameters.
Task submission
❗ Before getting started with this step, ensure that your EOA address is allowlisted with Newton Protocol. The EOA signer is represented by the variable signer in the snippet below. Please reach out to [email protected] to get the wallet allowlisted.
Once a policy is configured by an end-user, a task can be submitted.Here, an intent representing a transaction is constructed and sent to Newton Protocol along with the corresponding policy client address.
This portion of the SDK should be executed server-side (since it requires a private key to sign messages).Steps:
The EOA used must be allowlisted.
- Install the Newton Protocol SDK
→ @magicnewton/newton-protocol-sdk - Sign up with Alchemy (or another RPC provider) for a WebSocket URL.
- Implement the SDK per the below example.
In order to generate the
functionSignature and data fields, you can refer to the sample code below.