Guides

Create a mirror

🚧

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 mirror via Lens Profile Manager

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

Request

OnchainMirrorRequest

Invocation

const result = await client.publication.mirrorOnchain({
  mirrorOn: '0x123-0x456',
});
mutation MirrorOnchain($request: OnchainMirrorRequest!) {
  result: mirrorOnchain(request: $request) {
    ... on RelaySuccess {
      ...RelaySuccess
    }
    ... on LensProfileManagerRelayError {
      ...LensProfileManagerRelayError
    }
  }
}

Response

RelaySuccess or LensProfileManagerRelayError


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

Request

OnchainMirrorRequest

Invocation

const resultTypedData = await client.publication.createOnchainMirrorTypedData({
  mirrorOn: '0x123-0x456',
});
mutation CreateOnchainMirrorTypedData($request: OnchainMirrorRequest!, $options: TypedDataOptions) {
  result: createOnchainMirrorTypedData(request: $request, options: $options) {
    ...CreateOnchainMirrorBroadcastItemResult
  }
}

Response

CreateOnchainMirrorBroadcastItemResult

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

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

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}`);