5.6 KiB
seo, labels
| seo | labels | ||||
|---|---|---|---|---|---|
|
|
Create Permissioned Domains
Permissioned domains are controlled environments within the broader ecosystem of the XRP Ledger blockchain. Domains restrict access to other features such as Permissioned DEXes and Lending Protocols, only allowing access to them for accounts with specific credentials.
This example shows how to:
- Issue a credential to an account.
- Create a permissioned domain with the issued credential.
- Delete the permissioned domain.
Download the Modular Tutorials folder.
{% admonition type="info" name="Note" %} Without the Modular Tutorial Samples, you will not be able to try the examples that follow. {% /admonition %}
Get Accounts
To get test accounts:
- Open
create-permissioned-domains.htmlin a browser. - Get test accounts.
- If you copied the gathered information from another tutorial:
- Paste the gathered information to the Result field.
- Click Distribute Account Info.
- If you have an existing account seed:
- Paste the account seed to the Account 1 Seed or Account 2 Seed field.
- Click Get Account 1 from Seed or Get Account 2 from Seed.
- If you do not have existing accounts:
- Click Get New Account 1.
- Click Get New Account 2.
- If you copied the gathered information from another tutorial:
Issue a Credential
- Click the Account 1 radial button. This account will be the credential issuer.
- Copy the account 2 address into Subject.
- Enter a Credential Type. For example, KYC.
- Click Create Credential.
Create a Permissioned Domain
- Click Create Permissioned Domain.
- Copy the LedgerIndex value from the metadata response.
- (Optional) Update the permissioned domain with a different credential.
- Change the Credential Type.
- Click Create Credential.
- Copy the LedgerIndex value into DomainID.
- Click Create Permissioned Domain.
Delete a Permissioned Domain
- Copy the LedgerIndex value into DomainID.
- Click Delete Permissioned Domain.
Code Walkthrough
credential-manager.js
Create Credential
Define a function that issues a credential to a subject and connects to the XRP Ledger.
{% code-snippet file="/_code-samples/modular-tutorials/credential-manager.js" language="js" from="// Create credential function" before="// Gather transaction info" /%}
Gather the issuer information, subject, and credential type. Convert the credential type value to a hex string if not already in hex. Wrap the code in a try-catch block to handle errors.
{% code-snippet file="/_code-samples/modular-tutorials/credential-manager.js" language="js" from="// Gather transaction info" before="// Submit transaction" /%}
Submit the CredentialCreate transaction and report the results. Parse the metadata response to return only relevant credential info.
{% code-snippet file="/_code-samples/modular-tutorials/credential-manager.js" language="js" from="// Submit transaction" /%}
permissioned-domain-manager.js
Create Permissioned Domain
Define a function that creates a permissioned domain and connects to the XRP Ledger.
{% code-snippet file="/_code-samples/modular-tutorials/permissioned-domain-manager.js" language="js" from="/// Create permissioned domain" before="// Gather transaction info" /%}
Gather issuer information, credential type, and domain ID. Format the transaction depending on if the optional domain ID field is included. Wrap the code in a try-catch block to handle errors.
{% code-snippet file="/_code-samples/modular-tutorials/permissioned-domain-manager.js" language="js" from="// Gather transaction info" before="// Submit transaction" /%}
Submit the PermissionedDomainSet transaction and report the results. The metadata is formed differently if a domain ID was included; parse the response accordingly.
{% code-snippet file="/_code-samples/modular-tutorials/permissioned-domain-manager.js" language="js" from="// Submit transaction" before="// End create permissioned domain" /%}
Delete Permissioned Domain
Define a function to delete a permissioned domain and connect to the XRP Ledger.
{% code-snippet file="/_code-samples/modular-tutorials/permissioned-domain-manager.js" language="js" from="// Delete permissioned domain" before="// Get delete domain transaction info" /%}
Gather account information and domain ID values. Wrap the code in a try-catch block to handle errors.
{% code-snippet file="/_code-samples/modular-tutorials/permissioned-domain-manager.js" language="js" from="// Get delete domain transaction info" before="// Submit delete domain transaction" /%}
Submit the PermissionedDomainDelete transaction and report the results.
{% code-snippet file="/_code-samples/modular-tutorials/permissioned-domain-manager.js" language="js" from="// Submit delete domain transaction" /%}




