3. Permission smart contracts

This step is optional. Client can use Keyring's Pro and Connect onboardings without the on-chain credentials component.

How to permission contracts?

Any smart contract function can be permissioned with a modifier, allowing only whitelisted wallets to perform the underlying action. Examples of functions you can gate:

How to implement Keyring Permissioning?

You can create your own hooks or modifiers to include a guard in your contracts. You simply read from Keyring the status of an address with respect to a policy. This is a flexible and easy way to customise the integration to your needs.

Here is an example implementation:

Let's assume we want to guard an ERC20 transfer function.

Firstly, define the Keyring interface for checking credentials.

Secondly, define the Policy ID and the Keyring address in the contract constructor. You may optionally define a Whitelist mapping with associated values.

Then, override the functions that need permissioning. In this example OpenZepplin 5.0.2 is used for the base ERC20 implementation and so we override the _update function in order to perform a Keyring check.

Last updated