Skip to main content

DID

create(name, address, seed)

Parameters:

  • name REQUIRED <string>: DID name.

  • address <string>: DID address.

  • seed <string>: seed phrase.

  • callback <function>: for error handling.

This function creates DID (i.e. DIDs, MachineIds, peaqIDs) based on provided parameters. Function returns the generated peaq DID.

Code example


import { Sdk } from "@peaq-network/sdk";
import { mnemonicGenerate } from "@polkadot/util-crypto";

const generateMnemonicSeed = () => {
const mnemonicSeed = mnemonicGenerate();
return mnemonicSeed;
};

const createPeaqDID = async (name, seed) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
seed
});

const { hash } = await sdkInstance.did.create({
name,
});

await sdkInstance.disconnect();

return hash;
};

// Example usage
const name = 'myDID';
// you need to have balance with this seed.
const mnemonicSeed = generateMnemonicSeed();
// before creating your DID, you should have some // balance in your generated seed.
createPeaqDID(name, mnemonicSeed)
.then((hash) => {
console.log(`Created peaq DID: ${hash}`);
})
.catch((error) => {
console.error(`Error creating peaq DID: ${error}`);
});

NOTE

If the user has already passed the seed at the time of creating the SDK instance, then it is not necessary to pass it again at the time of creating the DID. In this case, address parameter can also be omitted.

Response object


{

"hash":"0x23738171cf9328d2c2214867e9720f436c2e91bc6274e78a4a2cec19222aab09"

}
INFORMATION

The hash is a value obtained after the peaq DID is created on the chain, and it is derived from the peaq DID document. The peaq DID document includes the peaq DID name and user public address, among other information.

read(name, address)

Parameters:

  • name REQUIRED <string>: name of DID.

  • address : user wallet address.

This function retrieves information linked to a registered DID on the blockchain. Returns json object with DID information.

NOTE

If the user has already passed the seed at the time of creating the SDK instance, then it is not necessary to pass address when reading DID.

Code example


import { Sdk } from '@peaq-network/sdk';
import { mnemonicGenerate } from "@polkadot/util-crypto";

const generateMnemonicSeed = async () => {
return mnemonicGenerate();
};

const createSDKInstance = async () (baseUrl, seed) => {
try {
const sdkInstance = await Sdk.createInstance({ baseUrl, seed });
return sdkInstance;
} catch (error) {
console.error(`Failed to create SDK instance: ${error}`);
throw error;
}
};

const readDID = async (sdk, name) => {
const mnemonicSeed = await
generateMnemonicSeed();
const did = await sdk.did.read(name, mnemonicSeed);
console.log(did);
};

// example usage
const exampleUsage = async () => {
const sdk = await createSDKInstance('wss://wsspc1-qa.agung.peaq.network');
const name = 'DIDName';
await readDID(sdk, name);
await sdk.disconnect();
};

// run example usage
exampleUsage();



Response object


{
"name":"test-did-14",
"value":"0x0a3964...316433",
"created":"1,682,100,174,024",
"document":{
"id":"did:peaq:5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"controller":"did:peaq:5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"verificationmethodsList":[
{
"id":"dc4702d6-71e7-4571-adb4-a7cd4945e1d3",
"type":0,
"controller":"did:peaq:z5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"publickeymultibase":"z5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
}
],
"servicesList":[

],
"authenticationsList":[
"dc4702d6-71e7-4571-adb4-a7cd4945e1d3"
]
}
}


  • name: The name of the DID given when creating the DID. This is a human-readable name that can be used to identify the DID.

  • value: The value of a peaq DID is a hash of the peaq DID document. The peaq DID document contains the DID name and the user's public address, among other information.

  • created: The block number when the DID was created. This provides a timestamp for when the DID was added to the blockchain.

  • document:

    • id: peaq DID followed by user public address.

    • controller: The controller of the DID. This is the did of the entity that has control over the DID, and can make updates or revoke the DID if necessary.

    • publickeymultibase: user public address.