---
updatedAt: 2025-07-26T14:22:17.000Z
agentTools:
  projectIndex: https://docs.metakeep.xyz/llms.txt
---

# Get Consent

## Getting the `ConsentRequestToken`

[Invoke Lambda](https://docs.metakeep.xyz/reference/v2applambdainvoke) requests initiated by developers on behalf of the users result in a `consentToken`.

```json Sample Transfer API Response
{
  "status": "USER_CONSENT_NEEDED",
  "consentToken": "CrgBAQIDAHgtrXLM76dJyt4f1olcBlk7ncpU7dew9F1vRFXlKBw-fJA-TfATHhYppUrIuoEMsncIpxm4af4uUh4Cikr2YkEzasNQr9433Z-V73Hw=="
}
```

## Getting the consent from users

Now that you've received the consent token from your backend, you can ask the user to provide consent by using `getConsent` function in MetaKeep SDK.

> 🚧 Consent token validity
>
> Note that the consent token once issued, is valid only for 10 minutes. SDK will throw an error if you try to use the consent token outside the expiration window.

`getConsent` returns a promise which succeeds when the consent operation is successful. You can handle this with a wrapper like so-

```javascript Calling &#x60;getConsent&#x60; API
/* 
	 Call getConsent. It returns a promise which resolves into a transaction data when the operation succeeds.
   Otherwise throws an error.
*/
async function getConsentFromMetakeepSDK(consentToken) {
  try {
    const consentResponse = await sdk.getConsent(consentToken);
    console.log("getConsent successful");
    console.log(consentResponse);
  } catch (err) {
    console.log("Error when trying to get consent");
    console.log(err);
  }
}
```

Now, call the above function with the `consentToken` from the backend transfer function.

```javascript
getConsentFromMetakeepSDK("CrgBAQIDAHgtrXLM76dJyt4f1olcBlk7ncpU7dew9F1vRFXlKBw-fJA-TfATHhYppUrIuoEMsncIpxm4af4uUh4Cikr2YkEzasNQr9433Z-V73Hw==");
```

Here's a reference implementation of this code: <https://jsfiddle.net/passbird/5gxn4y8h/>

On successful consent from user, `await sdk.getConsent(consentToken)` results in a successful transaction response.

```json EVM response
{
  status: "QUEUED",
  transactionChainScanUrl: "https://mumbai.polygonscan.com/tx/0x66bb55bfe89b071c9ae526fa451ff58d3bcc688e7b0618fbac2080cc2ba1437d",
  transactionHash: "0x66bb55bfe89b071c9ae526fa451ff58d3bcc688e7b0618fbac2080cc2ba1437d",
  transactionId: "695a704c-d01b-4e02-978a-1767b31dde46"
}
```
```json Solana response
{
  "status": "QUEUED",
  "transactionId": "e1e3af7e-de1c-48b7-9f3a-35bfcc13bbed",
  "transactionSignature": "2J4qDKhuwtUBYQC371xgp5CE3kQv7JqZGR3YyvGQf7BUUYWdapnj1cfUTTnvbpY3KcA5Y63bQ9eWeMvpC6UpHPJ9",
  "transactionChainScanUrl": "https://explorer.solana.com/tx/2J4qDKhuwtUBYQC371xgp5CE3kQv7JqZGR3YyvGQf7BUUYWdapnj1cfUTTnvbpY3KcA5Y63bQ9eWeMvpC6UpHPJ9?cluster=devnet"
}
```
```json Solana lambda batch response
{
  "status": "QUEUED",
  "transactions": [
    {
      "status": "QUEUED",
      "transactionId": "38cae336-9bc2-4b69-9141-3c85edf26f28",
      "transactionSignature": "3MRukZUmWhn6kKisa49fQXLu8sZWR5FuyoPczmmPgvaxwDZttxgrHheWADN2HH6vo8wZnCTDc2X1BmWwtzVMvsrS",
      "transactionChainScanUrl": "https://explorer.solana.com/tx/3MRukZUmWhn6kKisa49fQXLu8sZWR5FuyoPczmmPgvaxwDZttxgrHheWADN2HH6vo8wZnCTDc2X1BmWwtzVMvsrS?cluster=devnet"
    },
    {
      "status": "QUEUED",
      "transactionId": "94be5e32-744e-458f-b8f5-d6882360816c",
      "transactionSignature": "3tCRSonjNK6DyKWGb6sdc9i29j8VU6GMFndAtNF4xFh6kVDFihsoWvhSP9xNMP3KwWWk4Lug5zAtHv9LgewMjBdk",
      "transactionChainScanUrl": "https://explorer.solana.com/tx/3tCRSonjNK6DyKWGb6sdc9i29j8VU6GMFndAtNF4xFh6kVDFihsoWvhSP9xNMP3KwWWk4Lug5zAtHv9LgewMjBdk?cluster=devnet"
    },
    {
      "status": "QUEUED",
      "transactionId": "df2294c0-24af-4cc1-afa3-0f2c89ec8b85",
      "transactionSignature": "2S3RaKieYzg7abV85nL4CJNWtQpYAg4PJ4yVGpQP1u6wXq5uy4H9roiH2pF1MPPpQB2JeqoANjsFnLtM7wiUtr2h",
      "transactionChainScanUrl": "https://explorer.solana.com/tx/2S3RaKieYzg7abV85nL4CJNWtQpYAg4PJ4yVGpQP1u6wXq5uy4H9roiH2pF1MPPpQB2JeqoANjsFnLtM7wiUtr2h?cluster=devnet"
    }
  ]
}
```

You can now use the `transactionId` in the [Transaction Status](https://docs.metakeep.xyz/reference/v1apptransactionstatus) endpoint in the backend. MetaKeep invisibly ensures and applies several strategies to ensure the transactions are accepted and executed on the blockchain at the lowest gas possible.

## Idempotency Key

MetaKeep's infrastructure allows you to safely retry `getConsent` with the same idempotency key provided during the backend API call. This ensures that you don't accidentally performing the same operation twice. For e.g., you can generate 2 consent tokens for [Invoke Lambda](https://docs.metakeep.xyz/reference/v2applambdainvoke)  using the same idempotency key and then you can call `getConsent` twice using 2 different consent tokens. The transaction execution will **only happen once**.

## Error status

`getConsent` returns a promise which throws an error when the consent operation is unsuccessful. The error object looks like so-

```json Error object
{
  status: "USER_CONSENT_DENIED"
}
```

Here's a table of all possible error status returned by the SDK

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Status
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        USER\_CONSENT\_DENIED
      </td>

      <td>
        User has denied the consent request.
        In this case, you should ask the user if they want to try again.
      </td>
    </tr>

    <tr>
      <td>
        EXPIRED\_TOKEN
      </td>

      <td>
        Consent token has expired.
        You should get a new consent token from your backend.
      </td>
    </tr>

    <tr>
      <td>
        INVALID\_CONSENT\_TOKEN
      </td>

      <td>
        Consent token is invalid.
        Make sure you get the consent token from the correct backend APIs.
      </td>
    </tr>

    <tr>
      <td>
        APP\_NOT\_FOUND
      </td>

      <td>
        Provided app id is invalid.
        You can find the correct app id in the MetaKeep Developer Console.
      </td>
    </tr>

    <tr>
      <td>
        ISSUER\_DOES\_NOT\_MATCH
      </td>

      <td>
        You are trying to use consent token from `dublin`  environment in `prod` environment.
      </td>
    </tr>

    <tr>
      <td>
        SOMETHING\_WENT\_WRONG
      </td>

      <td>
        Unknown error happened.
        Please get in touch with us if you continue seeing this error.
      </td>
    </tr>
  </tbody>
</Table>

© Copyright 2024, Passbird Research Inc.