Guides

Create a comment

🚧

This request is protected by authentication

πŸ“˜

Lens Profile Manager Compatible: Gasless & Signless

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

a) Create a comment via Lens Profile Manager

If possible, using the Lens Profile Manager is the best way to create a comment. This will be a gasless and signless operation.

Request

OnchainCommentRequest

Invocation

const result = await client.publication.commentOnchain({
  commentOn: '0x123-0x456',
  contentURI: 'ipfs://Qm...', // or arweave
});
mutation CommentOnchain($request: OnchainCommentRequest!) {
  result: commentOnchain(request: $request) {
    ... on RelaySuccess {
      ...RelaySuccess
    }
    ... on LensProfileManagerRelayError {
      ...LensProfileManagerRelayError
    }
  }
}

Response

RelaySuccess or LensProfileManagerRelayError


b) Create a comment using TypedData and broadcasting Onchain via the API

Request

OnchainCommentRequest

Invocation

const resultTypedData = await client.publication.createOnchainCommentTypedData({
  commentOn: '0x123-0x456',
  contentURI: 'ipfs://Qm...', // or arweave
});
mutation CreateOnchainCommentTypedData(
  $request: OnchainCommentRequest!
  $options: TypedDataOptions
) {
  result: createOnchainCommentTypedData(request: $request, options: $options) {
    ...CreateOnchainCommentBroadcastItemResult
  }
}

Response

CreateOnchainCommentBroadcastItemResult

Broadcasting the TypedData

Once you have the typed data for the action, you need to get the user to sign with their wallet and then broadcast it onchain.

See Broadcasting Onchain for more information.


Full LensClient Example

Using the Lens Profile Manager:

// the client instance must be authenticated

const result = await client.publication.commentOnchain({
  commentOn: '0x123-0x456',
  contentURI: 'ipfs://Qm...', // or arweave
});

const resultValue = result.unwrap();

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

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

Using TypedData:

// the client instance must be authenticated

const resultTypedData = await client.publication.createOnchainCommentTypedData({
  commentOn: '0x123-0x456',
  contentURI: 'ipfs://Qm...', // or arweave
});

const { id, typedData } = resultTypedData.unwrap();

console.log(`Typed data: `, typedData);

// sign with the wallet
const signedTypedData = await wallet._signTypedData(
  typedData.domain,
  typedData.types,
  typedData.value,
);

console.log(`Broadcasting signed typed data...`);

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

const broadcastValue = broadcastResult.unwrap();

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

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