Guides

Collect (legacy)

🚧

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) Collect a publication via Lens Profile Manager

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

Request

LegacyCollectRequest

Invocation

const result = await client.publication.legacyCollect({
  on: '0x123-0x456',
});
mutation LegacyCollectPublication($request: LegacyCollectRequest!) {
  result: legacyCollect(request: $request) {
    ... on RelaySuccess {
      ...RelaySuccess
    }
    ... on LensProfileManagerRelayError {
      ...LensProfileManagerRelayError
    }
  }
}

Response

RelaySuccess or LensProfileManagerRelayError


b) Collect a publication using TypedData and broadcasting Onchain via the API

Request

Invocation

const resultTypedData = await client.publication.createLegacyCollectTypedData({
  on: '0x123-0x456',
});
mutation CreateLegacyCollectTypedData($request: LegacyCollectRequest!, $options: TypedDataOptions) {
  result: createLegacyCollectTypedData(request: $request, options: $options) {
    ...CreateLegacyCollectBroadcastItemResult
  }
}

Response

CreateLegacyCollectBroadcastItemResult

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.legacyCollect({
  on: '0x123-0x456',
});

const resultValue = result.unwrap();

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

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

console.log(`Waiting for the transaction to be indexed...`);
await client.transaction.waitUntilComplete({ txId: resultValue.txId });

Using TypedData:

// the client instance must be authenticated

const resultTypedData = await client.publication.createLegacyCollectTypedData({
  on: '0x123-0x456',
});

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

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

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 successfuly broadcasted with txId ${broadcastValue.txId}`);

// wait in a loop
console.log(`Waiting for the transaction to be indexed...`);
await client.transaction.waitUntilComplete({ txId: broadcastValue.txId });