Get Consent

Getting the ConsentRequestToken

NFT Transfer, Coin Transfer & Invoke Lambda requests initiated by developers on behalf of the users result in a consentToken.

  "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-

	 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");
  } catch (err) {
    console.log("Error when trying to get consent");

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


Here's a reference implementation of this code:

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

  status: "QUEUED",
  transactionChainScanUrl: "",
  transactionHash: "0x66bb55bfe89b071c9ae526fa451ff58d3bcc688e7b0618fbac2080cc2ba1437d",
  transactionId: "695a704c-d01b-4e02-978a-1767b31dde46"
  "status": "QUEUED",
  "transactionId": "e1e3af7e-de1c-48b7-9f3a-35bfcc13bbed",
  "transactionSignature": "2J4qDKhuwtUBYQC371xgp5CE3kQv7JqZGR3YyvGQf7BUUYWdapnj1cfUTTnvbpY3KcA5Y63bQ9eWeMvpC6UpHPJ9",
  "transactionChainScanUrl": ""

You can now use the transactionId in the Transaction Status 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 Coin Transfer operation using the same idempotency key and then you can call getConsent twice using 2 different consent tokens. The coin transfer 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-


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

USER_CONSENT_DENIEDUser has denied the consent request.
In this case, you should ask the user if they want to try again.
EXPIRED_TOKENConsent token has expired.
You should get a new consent token from your backend.
INVALID_CONSENT_TOKENConsent token is invalid.
Make sure you get the consent token from the correct backend APIs.
APP_NOT_FOUNDProvided app id is invalid.
You can find the correct app id in the MetaKeep Developer Console.
ISSUER_DOES_NOT_MATCHYou are trying to use consent token from dublin environment in prod environment.
SOMETHING_WENT_WRONGUnknown error happened.
Please get in touch with us if you continue seeing this error.

© Copyright 2024, Passbird Research Inc.