TypeScript Methods for ERC-721 Token Account Status

Blockchain App Builder automatically generates methods that you can use to manage account status for tokens that use the extended ERC-721 standard.

You can use the following methods to put token user accounts in the active, suspended, or deleted states.

When an account is suspended, the account user cannot complete any write operations, which include minting, burning, and transferring tokens. Additionally, other users cannot transfer tokens to a suspended account. A suspended account can still complete read operations.

An account with a non-zero token balance cannot be deleted. You must transfer or burn all tokens in an account before you can delete the account. After an account is in the deleted state, the account state cannot be changed back to active or suspended.

Automatically Generated Account Status Methods

getAccountStatus
This method gets the current status of the token account. This method can be called by the Token Admin of the chaincode or by the token account owner.
@Validator(yup.string(), yup.string())
     public async getAccountStatus(orgId: string, userId: string) {
       const accountId = await this.Ctx.ERC721Account.generateAccountId(orgId, userId);
       await this.Ctx.ERC721Auth.checkAuthorization("ERC721ACCOUNT_STATUS.get", "TOKEN", { accountId });
       try {
         return await this.Ctx.ERC721AccountStatus.getAccountStatus(accountId);
       } catch (err) {
        return await this.Ctx.ERC721AccountStatus.getDefaultAccountStatus(accountId);
       }
     }
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a JSON representation of the token account status. If no status is found in the ledger for the account because the account was created before the account status functionality was available, the status is listed as active in the response.
Return Value Example:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "active"
}
getAccountStatusHistory
This method gets the history of the account status. This method can be called by the Token Admin of the chaincode or by the token account owner.
public async getAccountStatusHistory(orgId: string, userId: string) {
       const accountId = await this.Ctx.ERC721Account.generateAccountId(orgId, userId);
       await this.Ctx.ERC721Account.getAccount(accountId);
       await this.Ctx.ERC721Auth.checkAuthorization("ERC721ACCOUNT_STATUS.history", "TOKEN", { accountId });
       const status_id = await this.Ctx.ERC721AccountStatus.generateAccountStatusId(accountId);
       let accountStatusHistory: any;
       try {
         accountStatusHistory = await this.Ctx.ERC721AccountStatus.history(status_id);
       } catch (err) {
         return [];
       }
       return accountStatusHistory;
     }
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, the account status history in JSON format.
Return Value Example:
[
  {
    "trxId": "d5c6d6f601257ba9b6edaf5b7660f00adc13c37d5321b8f7d3a35afab2e93e63",
    "timeStamp": "2022-12-02T10:39:14.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "suspended"
    }
  },
  {
    "trxId": "e6c850cfa084dc20ad95fb2bb8165eef3a3bd62a0ac867cccee57c2003125183",
    "timeStamp": "2022-12-02T10:37:50.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "active"
    }
  }
]
activateAccount
This method activates a token account. This method can be called only by a Token Admin of the chaincode. Deleted accounts cannot be activated. For any accounts created prior to the account status functionality being available, you must call this method to set the account status as active.
@Validator(yup.string(), yup.string())
 public async activateAccount(orgId: string, userId: string) {
   await this.Ctx.ERC721Auth.checkAuthorization("ERC721ACCOUNT_STATUS.activateAccount", "TOKEN");
   const accountId = await this.Ctx.ERC721Account.generateAccountId(orgId, userId);
   return await this.Ctx.ERC721Account.activateAccount(accountId);
 }
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a JSON representation of the token account status.
Return Value Example:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "active"
}
suspendAccount
This method suspends a token account. This method can be called only by a Token Admin of the chaincode. After an account is suspended, you cannot complete any operations that update the account. A deleted account cannot be suspended.
@Validator(yup.string(), yup.string())
 public async suspendAccount(orgId: string, userId: string) {
   await this.Ctx.ERC721Auth.checkAuthorization("ERC721ACCOUNT_STATUS.suspendAccount", "TOKEN");
   const accountId = await this.Ctx.ERC721Account.generateAccountId(orgId, userId);
   return await this.Ctx.ERC721Account.suspendAccount(accountId);
 }
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a JSON representation of the token account status.
Return Value Example:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "suspended"
}
deleteAccount
This method deletes a token account. This method can be called only by a Token Admin of the chaincode. After an account is deleted, you cannot complete any operations that update the account. The deleted account is in a final state and cannot be changed to any other state. To delete an account, the account balance must be zero.
@Validator(yup.string(), yup.string())
 public async deleteAccount(orgId: string, userId: string) {
   await this.Ctx.ERC721Auth.checkAuthorization("ERC721ACCOUNT_STATUS.deleteAccount", "TOKEN");
   const accountId = await this.Ctx.ERC721Account.generateAccountId(orgId, userId);
   return await this.Ctx.ERC721Account.deleteAccount(accountId);
 }
Parameters:
  • orgId: string – The membership service provider (MSP) ID of the user in the current organization.
  • userId: string – The user name or email ID of the user.
Returns:
  • On success, a JSON representation of the token account status.
Return Value Example:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "deleted"
}

Account Status SDK Methods

getAccountStatus
This method gets the current status of the token account.
Ctx.ERC721AccountStatus.getAccountStatus(accountId: string)
Parameters:
  • accountId: string – The ID of the token account.
Returns:
  • On success, a JSON representation of the token account status. If no status is found in the ledger for the account because the account was created before the account status functionality was available, the status is listed as active in the response.
Return Value Example:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "active"
}
getAccountStatusHistory
This method gets the history of the account status.
Ctx.ERC721AccountStatus.history(statusId: string)
Parameters:
  • statusId: string – The ID of the account status object.
Returns:
  • On success, a JSON representation of the account status history.
Return Value Example:
[
  {
    "trxId": "d5c6d6f601257ba9b6edaf5b7660f00adc13c37d5321b8f7d3a35afab2e93e63",
    "timeStamp": "2022-12-02T10:39:14.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "suspended"
    }
  },
  {
    "trxId": "e6c850cfa084dc20ad95fb2bb8165eef3a3bd62a0ac867cccee57c2003125183",
    "timeStamp": "2022-12-02T10:37:50.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "active"
    }
  }
]
activateAccount
This method activates a token account. For any accounts created prior to the account status functionality being available, you must call this method to set the account status as active.
Ctx.ERC721Account.activateAccount(accountId: string)
Parameters:
  • accountId: string – The ID of the token account.
Returns:
  • On success, a JSON representation of the account status object for the specified token account.
Return Value Example:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "active"
}
suspendAccount
This method suspends a token account.
Ctx.ERC721AccountStatus.suspendAccount(accountId: string)
Parameters:
  • accountId: string – The ID of the token account.
Returns:
  • On success, a JSON representation of the account status object for the specified token account.
Return Value Example:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "suspended"
}
deleteAccount
This method deletes a token account.
Ctx.ERC721Account.deleteAccount(accountId: string)
Parameters:
  • accountId: string – The ID of the token account.
Returns:
  • On success, a JSON representation of the account status object for the specified token account.
Return Value Example:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "deleted"
}