Answer the question
In order to leave comments, you need to log in
How to create Dapps (decentralized application) for a specific group of people?
Let's say we have a company that needs DP to be available only to them, they were not public. How to implement it?
Answer the question
In order to leave comments, you need to log in
You can put such functionality into a smart contract.
For example, you can make a couple of functions like grantAccess, revokeAccess, which will allow some wallet (address) access to a smart contract or revoke allowed access.
In these functions, make sure that only the owner of the wallet can call them, or whatever you decide.
And in all other functions of the smart contract, check whether access was previously granted or not.
Sample implementation:
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract ACL {
// тут храним кошельки, которые могут выдавать/отзывать полномочия админа.
mapping (address => bool) public admins;
// тут те, кому разрешен доступ
mapping (address => bool) public accessGranted;
constructor() {
// наделяем полномочиями админа того, кто деплоил контракт чтобы он потом мог выдать полномочия кому-то еще.
admins[msg.sender] = true;
}
function grantAdmin(address to) public {
require(admins[msg.sender] == true, "Forbidden");
admins[to] = true;
}
function revokeAdmin(address to) public {
require(admins[msg.sender] == true, "Forbidden");
delete admins[to];
}
function grantAccess(address to) public {
require(admins[msg.sender] == true, "Forbidden");
accessGranted[to] = true;
}
function revokeAccess(address to) public {
require(admins[msg.sender] == true, "Forbidden");
delete accessGranted[to];
}
// эта функция доступна всем
function publicOK() public pure returns (string memory) {
return "public OK";
}
// эта доступна только тем, кому был предоставлен доступ
function protectedOK() public view returns (string memory) {
require(accessGranted[msg.sender] == true, "Forbidden");
return "protected OK";
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question