Post
Share your knowledge.
How can I implement whitelist access in sui move?
I'm trying to set up access control in Sui Move similar to how it's done in Ethereum Solidity. In Solidity, a contract ensures that only whitelisted addresses can call certain functions. You set up a whitelist and check against msg.sender during cross-contract interactions. How can I achieve similar functionality in Sui Move with package-to-package access control?
- Move CLI
Answers
2In Sui Move, you can achieve similar access control by minting a 'WhiteListCap' object for the entities that should have access. Here's how it works:
- Define a struct for
WhiteListCap
that includes an UID field. - Create an 'AdminCap' that is required for minting new whitelist entries.
- The admin can call a function to generate a
WhiteListCap
and transfer it to a specific address. - Function calls that should be restricted can require a
WhiteListCap
parameter to ensure only whitelisted entities can execute them .
However, revoking access in Sui Move might be tricky since the admin loses control over the WhiteListCap
once transferred.
If you’re working with smart contracts or packages that may need iterative updates, be aware that Sui Move packages are immutable. Ensure you implement upgrade-friendly code patterns, like managing object-level permissions rather than package-level, and consider using version-based access controls .
Do you know the answer?
Please log in and share it.
Move is an executable bytecode language used to implement custom transactions and smart contracts.