Guides

Block Profiles

🚧

This request is protected by authentication

hint: this means it requires an x-access-token header put in the request with your authentication token.

📘

Lens Profile Manager Compatible: Gasless & Signless

This action can be used through the Lens Profile Manager to enable a gasless and signless experience.

Block a Lens Profile to restrict the authenticated user from any form of interaction with it.

This method can be used to block one or many profiles in a single call.

There are two different approaches you can use to block a profile. Depending on the whitelist status of your app and the settings of the profile you would like to set metadata for, you can use:

  • a) Block Profile via Lens Profile Manager (Gasless & Signless)
  • b) Block Profile Using TypedData and Broadcasting Onchain via the API (Gasless & Signed)

To decide which approach to use, you can use the following table. Please note that a profile may also have another Profile Manager enabled that is not powered by the Lens API, this is not covered below. To learn more about checking a profile's Profile Manager settings, see Profile Manager.

Is Your App Whitelisted?Profile has Lens Profiles Manager Enabled?Approach To Use
1truetrueLens Profile Manager
2truefalseTypedData & Broadcast via API
3falsetrueTypedData & Self-Funded
4falsefalseTypedData & Self-Funded

a) Block Profile via Lens Profile Manager (Gasless & Signless)

Request

  • profiles: ProfileId[] (required)
    • The profile IDs to block. ProfileId is a string.

Invocation

const result = await lensClient.profile.block({
  profiles: ["PROFILE_ID_TO_BLOCK"],
});
mutation Block {
  block(request: { profiles: ["PROFILE_ID_TO_BLOCK"] }) {
    ... on RelaySuccess {
      ...RelaySuccess
    }
    ... on LensProfileManagerRelayError {
      ...LensProfileManagerRelayError
    }
  }
}

Response

{
  "txHash": "0x000000",
  "txId": "0x01"
}
{
  "reason": "FAILED" // LensProfileManagerRelayErrorReasonType
}

Full Lens Client Example

const result = await lensClient.profile.block({
  profiles: ["PROFILE_ID_TO_BLOCK"],
});

const data = result.unwrap();

if (!isRelaySuccess(data)) {
  console.log(`Something went wrong`, data);
  return;
}

await lensClient.transaction.waitUntilComplete({ txId: data.txId });

b) Block Profile Using TypedData and Broadcasting Onchain via the API (Gasless & Signed)

Request

  • profiles: ProfileId[] (required)
    • The profile IDs to block. ProfileId is a string.

Invocation

const blockProfilesTypedData =
  await lensClient.profile.createBlockProfilesTypedData({
    profiles: ["PROFILE_ID_TO_BLOCK"],
  });
mutation CreateBlockProfilesTypedData($request: BlockRequest!) {
  createBlockProfilesTypedData(request: $request) {
    id
    expiresAt
    typedData {
      types {
        SetBlockStatus {
          name
          type
        }
      }
      domain {
        name
        chainId
        version
        verifyingContract
      }
      value {
        nonce
        deadline
      }
    }
  }
}

Response

{
  "id": "0x01",
  "expiresAt": "2023-10-01T00:00:00Z",
  "typedData": {
    "types": {
      "SetBlockStatus": [
        { "name": "nonce", "type": "uint256" },
        { "name": "deadline", "type": "uint256" },
        { "name": "profileIds", "type": "uint256[]" },
        { "name": "blockStatus", "type": "bool" }
      ]
    },
    "domain": {
      "name": "Lens",
      "chainId": "1",
      "version": "1",
      "verifyingContract": "0x0000000"
    },
    "value": {
      "nonce": "0x01",
      "deadline": "2023-10-01T01:00:00Z",
      "profileIds": ["0x01"],
      "blockStatus": true
    }
  }
}

Full Lens Client Example

const blockProfilesTypedData =
  await lensClient.profile.createBlockProfilesTypedData({
    profiles: ["PROFILE_ID_TO_BLOCK"],
  });

const data = blockProfilesTypedData.unwrap();

const signedTypedData = await wallet._signTypedData(
  data.typedData.domain,
  data.typedData.types,
  data.typedData.value
);

const broadcastResult = await lensClient.transaction.broadcastOnchain({
  id: data.id,
  signature: signedTypedData,
});

const broadcastResultValue = broadcastResult.unwrap();

if (!isRelaySuccess(broadcastResultValue)) {
  console.log(`Something went wrong`, broadcastResultValue);
  return;
}

await lensClient.transaction.waitUntilComplete({
  txId: broadcastResultValue.txId,
});

console.log(
  `Transaction was successfully broadcasted with txId ${broadcastResultValue.txId}`
);

Full GraphQL API Example

📘

Block Profile: GraphQL API Full Example