Create Profile
Testnet Only
This request is only available on testnet (mumbai). Creating a profile on mainnet is available through claiming a handle.
Create a new Lens profile with a specified handle.
There is no need to append test
or lens
to the handle you want to create. The contract will automatically append the correct extension based on the environment you are calling the contract from.
The best way to check if a handle is available is to send a getProfiles()
request filtered with handles
and the handle you want to check as the value.
Request
- handle:
CreateHandle
(required)- The handle to create the profile with. This handle must be unique and not already taken by another profile.
CreateHandle
is of type string.
- The handle to create the profile with. This handle must be unique and not already taken by another profile.
- to:
EvmAddress
(required)- The EVM wallet address to create the profile for.
EvmAddress
is of type string.
- The EVM wallet address to create the profile for.
- followModule:
FollowModuleInput
(optional)- The follow module to set for the profile.
FollowModuleInput
is of type object. - For more information on constructing the request for setting a profile's follow modules, see the Set Follow Module page.
- The follow module to set for the profile.
Invocation
const profileCreateResult = await lensClient.profile.create({
handle: "CHOSEN_HANDLE",
to: "YOUR_EVM_ADDRESS",
})
mutation CreateProfile {
createProfileWithHandle(
request: { handle: "CHOSEN_HANDLE", to: "EVM_ADDRESS" }
) {
... on RelaySuccess {
txHash
}
... on CreateProfileWithHandleErrorResult {
reason
}
}
}
Response
{
"txHash": "0x000000",
"txId": "0x01"
}
{
"reason": "FAILED" // CreateProfileWithHandleErrorReasonType
}
Full Lens Client Example
You can use LensClient SDK to create a new profile.
const handle = Date.now().toString()
console.log(`Creating a new profile for ${address} with handle "${handle}"`)
const profileCreateResult = await lensClient.profile.create({
handle: handle,
to: "YOUR_EVM_ADDRESS",
})
// profileCreateResult is a Result object
const profileCreateResultValue = profileCreateResult.unwrap()
if (!isRelaySuccess(profileCreateResultValue)) {
console.log(`Something went wrong`, profileCreateResultValue)
return
}
console.log(
`Transaction to create a new profile with handle "${handle}" was successfuly broadcasted with txId ${profileCreateResultValue.txId}`
)
console.log(`Waiting for the transaction to be indexed...`)
await lensClient.transaction.waitUntilComplete({
txId: profileCreateResultValue.txId,
})
const allOwnedProfiles = await lensClient.profile.fetchAll({
where: {
ownedBy: [address],
},
})
console.log(
`All owned profiles: `,
allOwnedProfiles.items.map((i) => ({ id: i.id, handle: i.handle }))
)
const newProfile = allOwnedProfiles.items.find(
(item) => item.handle === `${handle}.test`
)
if (newProfile) {
console.log(`The newly created profile's id is: ${newProfile.id}`)
}
Full GraphQL API Example
Updated about 1 month ago