Request Data
You can request data stored by any user on the Verida Network.
In this example we request the verifiable credential previously issued to ourselves.
Live Editor
VeridaRequestDataExample = () => {const [status, setStatus] = useState(null)const [veridaContext, setVeridaContext] = useState(undefined)const [credentialResponse, setCredentialResponse] = useState(undefined)this.CONTEXT_NAME = "Verida Tutorial"React.useEffect(async () => {// See the login example for an explaination of thisif (!veridaContext) {if (hasSession(this.CONTEXT_NAME)) {// we know we have a session already// globalLoginFunction is a globally defined version of the login function// See https://developers.verida.io/docs/tutorial/SSOlet ctx = await globalLoginFunction(this.CONTEXT_NAME);setVeridaContext(ctx);}}}, []);requestVC = async function () {setCredentialResponse(undefined)setStatus("Initalizing messaging... please wait.")const messaging = await veridaContext.getMessaging()// setup a listener to show the responsemessaging.onMessage(function(message) {console.log('New message:')console.log(message)setStatus('New message')setCredentialResponse(message)})setStatus("Creating request")const message = 'Please share your Verifiable Credential'const messageType = 'inbox/type/dataRequest'// note that credentialSchema used in the filter is the same schema we used when we issued the VC// userSelect: true lets the user select which VC to respond withconst data = {requestSchema: "https://common.schemas.verida.io/credential/base/v0.2.0/schema.json",filter: {credentialSchema: 'https://common.schemas.verida.io/health/pathology/tests/covid19/pcr/v0.1.0/schema.json'},userSelect: true}const config = {recipientContextName: 'Verida: Vault'}// This is the DID the message will go to// In this case it is the DID you are logged on here asconst requestFromDID = veridaContext.account.accountDidawait messaging.send(requestFromDID, messageType, data, message, config)setStatus("Request sent. Please check the Vault and share your VC")}let credentialMessage = <span></span>if (credentialResponse !== undefined) {// Note that this can have more than one credential in the response// We are only displaying the first here.credentialMessage = (<div><div>Summary: {credentialResponse.data.data[0].summary}</div><div>Credential Type: {credentialResponse.data.data[0].name}</div><div>Issued To: {credentialResponse.data.data[0].fullName}</div></div>)}let statusMessage = <div></div>if (status !== null) {statusMessage = (<div className="tutorial-status tutorial-status admonition admonition-info alert alert--info">{status}{credentialMessage}</div>)}// if we have a veridaContext we are logged inif (veridaContext) {// user is logged inreturn (<div>Please make sure you have <a href="/docs/tutorial/verifiable_credentials#runcode">issued yourself a verifiable credential</a> before requesting it.<br /><button onClick={this.requestVC}>Request Data</button>{statusMessage}</div>)} else {return (<div className="admonition admonition-danger alert alert--danger"><h2>Please login <a href="/docs/tutorial/SSO#runcode">here</a></h2></div>)}}
Result
Loading...