Links
Comment on page

Code Examples

This section contains multiple code examples you can use to improve your first dApp.

Read Credential and Schema Data from Vault+

const [credential, setCredential] = React.useState<Credential>("credential-id");
async function claimCredential()
{
console.log(`Running Serv.claimCredential("${credential}")...`);
const Result = await Serv.claimCertificate(certificate);
console.log(`Result: `, Result);
}

Claim a Credential through Vault+

function ClaimCredential() {
const [credentialId, setCrendentialId] = React.useState(
"0x7e417ae78bea0b6e301713f3211bc64f9c525986990c99180b77a2ec7da6155beac157b2f9ff9fe18d12cce5fd093ce280bf630074f5e5b29e8882767d361a81"
);
async function claimCredential() {
console.log(`running "Serv.claimCredential("${credentialId}")"...`);
const response = await Serv.claimCredential(credentialId);
console.log(
`response "Serv.claimCredential("${credentialId}")": `,
response
);
}
return (
<>
<h3>Claim Credential</h3>
<p>
<code>
const response = await Serv.claimCredential("{credentialId}");
</code>
</p>
<form
onSubmit={(event) => {
event.preventDefault();
claimCredential();
}}
>
<input
value={credentialId}
onChange={(event) => setCrendentialId(event.target.value)}
/>
<button type="submit">Trigger</button>
</form>
</>
);
}
To obtain example values for "credential-id" you can look up Schemas on the Mantis schema marketplace. Each of them is a separate certificate that can later be queried with queryCredentials() or verifyClaim() from the Vault+ SDK after the user has claimed the respective credential through Vault+.

Query Credential Data with queryCredentials()

function QueryCredentials() {
async function queryCredentials() {
const response = await Serv.queryCredentials(
"0x7e417ae78bea0b6e301713f3211bc64f9c525986990c99180b77a2ec7da6155beac157b2f9ff9fe18d12cce5fd093ce280bf630074f5e5b29e8882767d361a81",
["first_name", "last_name", "dob"]
);
console.log(response);
}
return (
<>
<h3>Query Credentials</h3>
<p>
<code>const response = await Serv.queryCredentials();</code>
</p>
<button onClick={() => queryCredentials()}>Trigger</button>
</>
);
}
The first_name, last_name, and dob fields are fields that are present on the credential that was previously claimed.

Verify Claims of a Credential

function VerifyClaims() {
async function verifyClaims() {
const response = await Serv.verifyClaims(
"0x7e417ae78bea0b6e301713f3211bc64f9c525986990c99180b77a2ec7da6155beac157b2f9ff9fe18d12cce5fd093ce280bf630074f5e5b29e8882767d361a81",
{
first_name: {
comparison: "contains",
value: "John",
},
last_name: {
comparison: "contains",
value: "Doe",
},
}
);
}
return (
<>
<h3>Verify Claims</h3>
<p>
<code>const response = await Serv.verifyClaims();</code>
</p>
<button onClick={() => verifyClaims()}>Trigger</button>
</>
);
}
The second argument that is passed into the verifyClaims functions is an object which contains validation requirements. The field names of the nested object are linked to the names of the credential fields. You can find a list of comparison options here.
Any one of the string values inside of the array can be used to run a validity check on a user's private data stored within a credential and the value key of the property is the value you are checking against.
Keep in mind that you can't run greaterThan or other numerical comparisons on strings!