Policy Definition
Now, we will create ourpolicy.json
file that defines our Policy. We have pre-created it for you here to match the described scenario. For more information on how to configure policies yourself, check out the Policy Configuration Guide.
mint(address to, uint256 quantity)
, but the encodedValues
also includes an address owner
field. So, in this case we need to pack in additional data to send from the calling contract to the policy.
Also note the ForeignCalls
defined in the policy, which are used in the rule evaluation as well as an effect for the positive mint outcome path.
Generate and Add Modifiers
To add the modifiers to yourClaireNFT.sol
contract, create a new file named injectModifiers.ts
and add the content below.
You will need to have the SDK installed in your project. Check the installation
guide for details.
injectModifiers.ts
src/RulesEngineClientCustom.sol
and diff.diff
. It will also update the existing ClaireNFT.sol
file by adding the modifier to the mint
function.
The
diff.diff
file will show exactly what was changed in the ClaireNFT.sol
file for your
reference.policy.json
file, the modifier automatically added in the owner
field into the modifier file for you.
And that’s it! The ClaireNFT.sol contract is now ready to use for this policy.
Passing Additional Values to the Rules Engine
In the example above the rule condition requires the address of the contract owner to bypass the rule condition. Theowner
value is not a function argument and must be explicitly added to the modifier attached to the mint
function. This was accomplished by manually editing the RulesEngineClientCustom.sol
and ClaireNFT.sol (Updated)
files to include this extra function argument.
Refer to the code examples in the tabs above to see exactly how to do this. You can include any extra state variables in your smart contract that you want to leverage in your rule condition using this method.