Declarative rules are in early access and are not enabled by default. Talk to us if you’d like to participate.
/environments/<environment_id>/... and authenticate with a developer API token (<api_token>) for a user with the Admin role, or with a dashboard login. Writes need the environment settings write scope, and reads need the read scope.
Declarative rules must be enabled for your environment. Until they are, a declarative write returns 403 with rule_syntax_disabled.
The legacy environment endpoints on Creating & Managing Rules take legacy rules only. With declarative rules you can write the environment layer two ways:
- One rule at a time with
PATCH: add or update a rule, remove a rule, or apply several changes together. - The whole list with
PUT: send the layer’s full rule list, so anything you leave out is removed.
Read the layer
Read the current rules:Add or update a rule
PATCH with op: "upsert" adds a rule or updates one in place. Send the rule in declarativeRule. ruleId is optional: leave it out to create a rule, and the response returns the generated id in layerContent.rules. To update a rule, send its ruleId.
Both
PATCH and PUT edit a layer that already exists. The environment layer is created automatically, for example when the environment’s first wallet is created. Until it exists, both return 404.Remove a rule
Apply several changes at once
op: "batch" applies 1 to 100 upserts and removes together. They all succeed or none are applied.
Replace the whole list
Write the full list withPUT, or with PATCH and op: "replace" and a rules array. Any rule you leave out is removed, so keep the ruleId of every rule you are keeping. This example blocks one address and caps transactions at 5 ETH.
Good to know
- Edits are saved as they arrive and aren’t checked against what else changed. If two people edit the environment layer at the same moment, one change can overwrite the other. The account, wallet, and signer layers behave the same way.
- Until the layer holds its first declarative rule, a write to the legacy environment endpoints still overwrites it with the legacy rules. Once it holds a declarative rule, legacy writes leave it alone.
GET /sdk/<environment_id>/waas/env-policy-layer with their JWT.
Next steps
Rule examples
Ready-made declarative rules.
Creating & Managing Rules
The dashboard and the legacy environment API.
Managing layers
Account, wallet, and signer layers.