Link Handle To Profile
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.
Link a handle to an existing Lens Profile.
There are two different approaches you can use to link a handle to 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) Link Handle to Profile via Lens Profile Manager (Gasless & Signless)
- b) Link Handle to 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 | |
---|---|---|---|
1 | true | true | Lens Profile Manager |
2 | true | false | TypedData & Broadcast via API |
3 | false | true | TypedData & Self-Funded |
4 | false | false | TypedData & Self-Funded |
a) Link Handle to Profile via Lens Profile Manager (Gasless & Signless)
Request
handle: Handle
(required)- The handle of to link to the Lens Profile.
Handle
is a string.
- The handle of to link to the Lens Profile.
Invocation
await client.profile.linkHandle({
handle: "HANDLE",
});
mutation HandleLinkToProfile {
handleLinkToProfile(request: { handle: "HANDLE" }) {
... on RelaySuccess {
txId
txHash
}
... on LensProfileManagerRelayError {
reason
}
}
}
Response
{
"txHash": "0x000000",
"txId": "0x01"
}
{
"reason": "FAILED" // LensProfileManagerRelayErrorReasonType
}
Full Lens Client Example
await client.profile.linkHandle({
handle: "HANDLE",
});
b) Link Handle to Profile Using TypedData and Broadcasting Onchain via the API (Gasless & Signed)
Request
handle: Handle
(required)- The handle of to link to the Lens Profile.
Handle
is a string.
- The handle of to link to the Lens Profile.
Invocation
const linkHandleToProfileTypedData =
await lensClient.profile.createLinkHandleTypedData({
handle: "HANDLE",
});
mutation CreateHandleLinkToProfileTypedData {
createHandleLinkToProfileTypedData(request: { handle: "HANDLE" }) {
id
expiresAt
typedData {
types {
Link {
type
name
}
}
domain {
name
chainId
version
verifyingContract
}
value {
nonce
deadline
profileId
handleId
}
}
}
}
Response
{
"id": "0x01",
"expiresAt": "2023-10-01T00:00:00Z",
"typedData": {
"types": {
"Link": [
{ "name": "nonce", "type": "uint256" },
{ "name": "deadline", "type": "uint256" },
{ "name": "profileId", "type": "uint256" },
{ "name": "handleId", "type": "uint256" }
]
},
"domain": {
"name": "Lens",
"chainId": "1",
"version": "1",
"verifyingContract": "0x0000000"
},
"value": {
"nonce": "0x01",
"deadline": "2023-10-01T01:00:00Z",
"profileId": "0x01",
"handleId": "0x01"
}
}
}
Full Lens Client Example
const linkHandleToProfileTypedData =
await lensClient.profile.createLinkHandleTypedData({
handle: "HANDLE",
});
const data = linkHandleToProfileTypedData.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
Updated about 1 month ago