2

We have our own chain where we've added pallet_contracts pallet for writing and deploying smart contract. We just want to give permission to upload smart contract for few users only. Someone please gives some advice how can we implement this features?

1 Answer 1

2

That's is a very interesting feature, I would like to see cool approaches and ideas in the responses of this question.

I don't think you can get this functionality with the current pallet_contracts (But I might be wrong). Anyone (or any program) that has tokens of the chain can upload a smart contract without requiring permission using this pallet.

I can think of two options here:

  1. The first one and the less recommended is to copy the code of the pallet into a new pallet custom_pallet_contracts and modify the code to let only authorised users upload the contract. For that you only need to create a new storage where you keep a list of all the users with permissions to upload contracts, and modify the upload_contract extrinsic in order to check that the origin is in that list.

  2. The second option is a bit more complex but definitely is the one I recommend to go. Create a new pallet that acts a "wrapper pallet" for the pallet_contract where you can add additional logic like check if the origin can upload the contract.

    The idea is not mine, is from Sergei and Shawn, and they created a tutorial about it 4 years ago: Extending Substrate Runtime Modules. You can see the code of this "wrapper pallet" here: Sudo Contract .

    The tutorial is amazing but is outdated so you won't probably be able to use the same code, but you will get the concept and understand the logic and the steps needed:

    • In your new pallet expose the same extrinsic calls as the pallet_contracts (in your case at least the upload_contract) and forwards those calls to the real pallet_contracts.
    • Before forwards those calls to the real pallet_contracts, add your authorization checks logic.
    • In your node make the pallet_contracts pallet "Un-Callable" so the upload_contract extrinsic has to be called within your "wrapper pallet"

Another example of this concept of extending functionality of a current pallet is the NFTs Royalty Pallet, which is a "wrapped pallet" that manages a royalties for the nft_pallet, locking the transfer in the nft_pallet and forcing users to make the NFT transfers within the nft_royalties_pallet that has some extra logic on top of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.