Using the initialized SDK instance, you can create a Decentralized Identifier (DID) on-chain, enabling identity-based operations within the peaq.

This operation generates a DID document and either:

  • Returns an unsigned transaction or extrinsic (if no signer is available), or
  • Submits the DID creation directly to the blockchain (if signing credentials are present).

create(name, custom_document_fields, address)

Enables the creation of a decentralized identity on-chain for your given entity.

ParameterTypeEVMSubstrateDescription
namestringRequiredRequiredName of the DID to be created.
custom_document_fieldsCustomDocumentFieldsRequiredRequiredSets specific fields of the DID Document.
addressstringRequired*Required*Wallet address that is used to create the DID Document. If seed has been set, defaults to the corresponding public key address.

* The address is required when no seed is set.

CustomDocumentFields

ParameterTypeEVMSubstrateDescription
verificationsVerification[]OptionalOptionalStores the verification method that is tied to the wallet used to create this DID Document.
signatureSignatureOptionalOptionalUsed to store an issuer’s signature.
servicesServices[]OptionalOptionalLinks data, endpoints, or other metadata to the DID Document.

Verification

ParameterTypeEVMSubstrateDescription
typestringOptionalOptionalAllows user to manually set the type of verification to be used with the public key tied to the DID Document.

EVM Wallets:
- EcdsaSecp256k1RecoveryMethod2020
Substrate Wallets:
- Ed25519VerificationKey2020
- Sr25519VerificationKey2020
publicKeyMultibasestringOptionalOptionalAllows user to manually set the public Key MultiBase they would like to use for their verification method.

Signature

ParameterTypeEVMSubstrateDescription
typestringRequiredRequiredThe algorithm used when generating a signature.
issuerstringRequiredRequiredEntity that issued the signature.
hashstringRequiredRequiredHash value of the generated signature.

Services

ParameterTypeEVMSubstrateDescription
idstringRequiredRequiredIdentifier used to indicate what type of service is being used.
typestringRequiredRequiredDeclares the type of service object being referenced.
serviceEndpointstringOptionalOptionalURI/URL that is used to point to another data storage location.
datastringOptionalOptionalData value that can be stored at this service.

Create DID Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType, CustomDocumentFields, Verification, Service, Signature

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")
EVM_ADDRESS = os.getenv("EVM_ADDRESS")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

name = 'DID_NAME_001'

response = sdk.did.create(
    name=name, 
    custom_document_fields=
        CustomDocumentFields(
            verifications=[Verification(type='EcdsaSecp256k1RecoveryMethod2020')],
            signature=Signature(type='EcdsaSecp256k1RecoveryMethod2020', issuer='0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C', hash='123'),
            services=[Service(id='#ipfs', type='peaqStorage', data='123')]
        ),
    address=EVM_ADDRESS
    )

read(name, address)

Allows a user to read a previously created DID from the chain.

ParameterTypeEVMSubstrateDescription
namestringRequiredRequiredName of the DID stored.
addressstringRequired*Required*Address of the wallet that created the DID Document.

* The address is required when no seed is set.

Read DID Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")
EVM_ADDRESS = os.getenv("EVM_ADDRESS")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

name = 'DID_NAME_001'

document = sdk.did.read(name=name, address=EVM_ADDRESS)

update(name, custom_document_fields, address)

Updates an existing DID identified by name, overwriting the entire DID document with new custom_document_fields. Use caution, as all existing data is replaced with the newly provided fields. Recommended to use the read method to view the current DID document before updating.

ParameterTypeEVMSubstrateDescription
namestringRequiredRequiredName of the DID to be updated.
custom_document_fieldsCustomDocumentFieldsRequiredRequiredNew fields to embed in the DID Document. These fully replace the prior document.
addressstringRequired*Required*Wallet address that owns the DID Document. If seed has been set, defaults to the corresponding public key address.

* The address is required when no seed is set.

Update DID Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType, CustomDocumentFields, Verification, Service, Signature

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")
EVM_ADDRESS = os.getenv("EVM_ADDRESS")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

name = 'DID_NAME_001'

response = sdk.did.update(
    name=name, 
    custom_document_fields=
        CustomDocumentFields(
            verifications=[Verification(type='EcdsaSecp256k1RecoveryMethod2020')],
            signature=Signature(type='EcdsaSecp256k1RecoveryMethod2020', issuer='0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C', hash='456'),
            services=[Service(id='#updated-ipfs', type='peaqStorage', data='updated-data')]
        ),
    address=EVM_ADDRESS
    )

remove(name, address)

Removes an existing on-chain DID identified by name. Once removed, the DID data is no longer accessible via subsequent reads.

ParameterTypeEVMSubstrateDescription
namestringRequiredRequiredName of the DID to be removed from the chain.
addressstringRequired*Required*Wallet address that owns the DID Document. If seed has been set, defaults to the corresponding public key address.

* The address is required when no seed is set.

Remove DID Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")
EVM_ADDRESS = os.getenv("EVM_ADDRESS")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

name = 'DID_NAME_001'

response = sdk.did.remove(name=name, address=EVM_ADDRESS)