🚧 This documentation is currently under development. Content may be incomplete or subject to change. 🚧
Skip to content

Viewers ​

Viewers are addresses that have permission to decrypt the data associated with a handle. Managing viewers is essential for controlling who can view the decrypted data.

INFO

An account which is a viewer for a handle can get the decrypted value of a handle with the decrypt method of the SDK.

Checking Viewers ​

The Nox protocol smart contract provides a function to check if a specific address is a viewer for a given handle:

solidity
function isViewer(bytes32 handle, address account) external view returns (bool);

isViewer ABI:

json
[
  {
    "inputs": [
      {
        "internalType": "bytes32",
        "name": "handle",
        "type": "bytes32"
      },
      {
        "internalType": "address",
        "name": "viewer",
        "type": "address"
      }
    ],
    "name": "isViewer",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  }
]
ts
const 
noxContract
= new
Contract
(
NOX_CONTRACT_ADDRESS
,
NOX_CONTRACT_ABI
,
provider
); const
isViewer
: boolean = await
noxContract
.
isViewer
(
handle
,
account
);
ts
const 
isViewer
= await
publicClient
.
readContract
({
address
:
NOX_CONTRACT_ADDRESS
,
abi
:
NOX_CONTRACT_ABI
,
functionName
: 'isViewer',
args
: [
handle
,
viewerAddress
],
});

Adding Viewers ​

The Nox protocol smart contract provides a function for admins to add a specific address as a viewer for a given handle:

INFO

Only allowed admins can add viewers. (see Manage Admins guide for more details on admins management).

WARNING

Once added, a viewer cannot be removed.

solidity
function addViewer(bytes32 handle, address account) external;

addViewer ABI:

json
[
  {
    "inputs": [
      {
        "internalType": "bytes32",
        "name": "handle",
        "type": "bytes32"
      },
      {
        "internalType": "address",
        "name": "viewer",
        "type": "address"
      }
    ],
    "name": "addViewer",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  }
]
ts
const 
noxContract
= new
Contract
(
NOX_CONTRACT_ADDRESS
,
NOX_CONTRACT_ABI
,
signer
); const
tx
= await
noxContract
.
addViewer
(
handle
,
viewerAddress
);
await
tx
.wait();
ts
const [
userAddress
] = await
walletClient
.
getAddresses
();
await
walletClient
.
writeContract
({
account
:
userAddress
,
chain
:
CHAIN
,
address
:
NOX_CONTRACT_ADDRESS
,
abi
:
NOX_CONTRACT_ABI
,
functionName
: 'addViewer',
args
: [
handle
,
viewerAddress
],
});