Skip to content

Commit

Permalink
Merge branch 'main' into add-base-uri-script
Browse files Browse the repository at this point in the history
  • Loading branch information
fhildeb authored Feb 23, 2024
2 parents dd145c1 + cb933e7 commit 3080ad8
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions universal-profile/get-controller-permissions.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
import { ERC725 } from '@erc725/erc725.js';
import LSP6Schema from '@erc725/erc725.js/schemas/LSP6KeyManager.json';

const myUniversalProfileAddress = '0xEda145b45f76EDB44F112B0d46654044E7B8F319';

// 💡 Note: You can debug any smart contract by using the ERC725 Tools
// 👉 https://erc725-inspect.lukso.tech/inspector?address=0xEda145b45f76EDB44F112B0d46654044E7B8F319&network=testnet

// https://docs.lukso.tech/networks/testnet/parameters
const RPC_ENDPOINT = 'https://rpc.testnet.lukso.network';

const erc725 = new ERC725(LSP6Schema, myUniversalProfileAddress, RPC_ENDPOINT);
// Instantiate erc725.js with a Universal Profile address on Testnet
const erc725 = new ERC725(
LSP6Schema,
// Sample Profile Address
'0xEda145b45f76EDB44F112B0d46654044E7B8F319',
// LUKSO Testnet RPC
'https://rpc.testnet.lukso.network',
);

// 💡 You can debug permissions from ERC725 Tools
// 👉 https://erc725-inspect.lukso.tech/key-manager

async function getPermissionedAddresses() {
// Get the list of addresses that have permissions on the Universal Profile
const result = await erc725.getData('AddressPermissions[]');
// https://docs.lukso.tech/standards/universal-profile/lsp6-key-manager/#permissions
// https://docs.lukso.tech/tools/erc725js/classes/ERC725#getdata
const controllerAddresses = await erc725.getData('AddressPermissions[]');

if (!result) {
console.error(
'No controllers listed under UP at address ',
myUniversalProfileAddress,
);
if (!controllerAddresses) {
console.error('No controllers listed under this Universal Profile ');
}

if (Array.isArray(result.value)) {
// Get the permissions of each address
for (let ii = 0; ii < result.value.length; ii++) {
const address = result.value[ii] as string;
if (Array.isArray(controllerAddresses.value)) {
// Get the permissions of each controller of the UP
for (let i = 0; i < controllerAddresses.value.length; i++) {
const address = controllerAddresses.value[i] as string;

// https://docs.lukso.tech/tools/erc725js/classes/ERC725#getdata
const addressPermission = await erc725.getData({
keyName: 'AddressPermissions:Permissions:<address>',
dynamicKeyParts: address,
Expand Down

0 comments on commit 3080ad8

Please sign in to comment.