Update Account Metadata

This guide will help you update Account details like profile picture, name, and bio.


To update Account Metadata, you need to:

  1. Create a new Account Metadata object.

  2. Upload the Account Metadata object onto a public URI.

  3. Set the URI of the Account Metadata on your Lens Account.

The first two steps are similar to the ones in the Create an Account guide so we'll keep them brief.

See the Lens Metadata Standards guide for more information on creating and hosting Metadata objects.

1

Create Account Metadata

First, create a new Account Metadata object with the updated details.

It's developer responsability to copy over any existing data that should be retained.

import { MetadataAttributeType, account } from "@lens-protocol/metadata";
const metadata = account({  name: "Jane Doe",  bio: "I am a photographer based in New York City.",  picture: "ipfs://bafybeigdyrzt5sfp7udm7hu76u…",  coverPicture: "ipfs://bafybeihqj6arccj5xiky5jf…",  attributes: [    {      key: "twitter",      type: MetadataAttributeType.STRING,      value: "https://twitter.com/janedoexyz",    },    {      key: "dob",      type: MetadataAttributeType.DATE,      value: "1990-01-01T00:00:00Z",    },    {      key: "enabled",      type: MetadataAttributeType.BOOLEAN,      value: "true",    },    {      key: "height",      type: MetadataAttributeType.NUMBER,      value: "1.65",    },    {      key: "settings",      type: MetadataAttributeType.JSON,      value: '{"theme": "dark"}',    },  ],});

2

Upload Account Metadata

Then, upload the Account Metadata object to a public URI.

Upload
import { account } from "@lens-protocol/metadata";import { uploadJson } from "./my-upload-lib";
const metadata = account({  name: "Jane Doe",});
const metadataURI = await uploadJson(metadata); // e.g., lens://4f91ca…

3

Set Account Metadata URI

Then, you can use the setAccountMetadata mutation to update the Account Metadata URI.

You MUST be authenticated as Account Owner or Account Manager to make this request.

mutation {  setAccountMetadata(request: { metadataUri: "lens://4f91ca…" }) {    ... on SetAccountMetadataResponse {      hash    }
    ... on SponsoredTransactionRequest {      ...SponsoredTransactionRequest    }
    ... on SelfFundedTransactionRequest {      ...SelfFundedTransactionRequest    }
    ... on TransactionWillFail {      reason    }  }}

Finally, handle the result as explained in the Transaction Lifecycle guide.