Create a post
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 post via Lens Profile Manager
If possible, using the Lens Profile Manager is the best way to create a post. This will be a gasless and signless operation.
Request
Invocation
const result = await client.publication.postOnchain({
contentURI: 'ipfs://Qm...', // or arweave
});
mutation PostOnchain($request: OnchainPostRequest!) {
result: postOnchain(request: $request) {
... on RelaySuccess {
...RelaySuccess
}
... on LensProfileManagerRelayError {
...LensProfileManagerRelayError
}
}
}
Response
RelaySuccess or LensProfileManagerRelayError
b) Create a post using TypedData and broadcasting Onchain via the API
Request
Invocation
const resultTypedData = await client.publication.createOnchainPostTypedData({
contentURI: 'ipfs://Qm...', // or arweave
});
mutation CreateOnchainPostTypedData($request: OnchainPostRequest!, $options: TypedDataOptions) {
result: createOnchainPostTypedData(request: $request, options: $options) {
...CreateOnchainPostBroadcastItemResult
}
}
Response
CreateOnchainPostBroadcastItemResult
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.postOnchain({
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.createOnchainPostTypedData({
contentURI: 'ipfs://Qm...', // or arweave
});
const { id, typedData } = resultTypedData.unwrap();
// 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}`);
Updated 2 days ago