In the Syndicate dashboard demo project users are able to relay transactions via the Syndicate API to call mint
on a demo contract. In this demo we'll show how we can define this restriction, and further restrictions within the Shield3 RPC.
On the Syndicate UI the project is configured as shown here:
Allowed Functions restricts the API to send mint
requests to the specified contact on the Mumbai testnet.
The payload to send the mint
request via the syndicate API is:
On Shield3 the contract restriction can be defined with a policy as follows. NOTE this shows the inner workings of the policy engine, the dashboard provides a simple editor to set these parameters without needing to learn the policy language.
permit | forbid
defines the only conditions that the RPC should broadcast the transaction. Policies can be configured to either allow everything except specific conditions, or allow nothing except specific conditions.
action
Can be blank, Notify
or MFA
. This instructs the RPC what to do in the event that the transaction is allowed. Alerts and MFA requests are sent via webhooks.
principal
defines which senders this policy applies to. Principal by itself means that it applies to all senders.
action
defines which transaction types this policy applies to. In this case the function signature of mint
is used.
resource
defines which contracts this policy applies to. In this case it is restricted to the mint contract address.
when
defines additional context. In this case it is restricting the policy to transactions on the Mumbai network.
This policy can be further extended to allow customers to restrict transactions to specific lists of recipients.
This policy includes an unless
case which checks if the recipient of the mint is on a deny list. These lists are configurable via the Shield3 API or dashboard.
Shield3 provides both broadcast
and simulate
capabilities to test the policy decision for a transaction. A broadcast
call follows the JSON RPC specification for all Ethereum nodes and no additional configuration is required except using the Shield3 RPC URL. Simulate
uses a custom RPC method. The api request looks like this for a valid mint request (function data is serialized using standard eth libs)
When we call the simulate
method with the above policy enabled on the account we get this response.
With an invalid request (such as a different contract method or a blocked recipient) we get this response
The policy above has been enabled on an account with this RPC URL, you can also log in here.
https://rpc.shield3.com/v3/0x013881/rpc?apiKey=9yOMT21nl259vFr82C3BT1BvMvGrK4eK7zOWFIX3
Now, we want to enable our policies in the Shield3 dashboard. First, make your way to the policies dashboard.
Now, you should be seeing series of policies. Simply press the drop-down icon on your desired policies, then select "enable". Custom policies can also be uploaded via API, or send us a message with a policy you'd like and we'll make it happen!
Configuring your webhook is also quite straight-forward. In this integration, the webhook will be used for MFA and any notifications arising from policy execution. Navigate to the webhooks page.
Next, press "create new webhook", then enter a name, description, and the URL to hit when the webhook is fired.