Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dabit3/lens-create-publication-example
An example project showing how to create a publication using withSig and typed data
https://github.com/dabit3/lens-create-publication-example
Last synced: about 1 month ago
JSON representation
An example project showing how to create a publication using withSig and typed data
- Host: GitHub
- URL: https://github.com/dabit3/lens-create-publication-example
- Owner: dabit3
- Created: 2022-11-02T15:48:06.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-03T15:09:45.000Z (about 2 years ago)
- Last Synced: 2024-08-03T16:09:35.339Z (5 months ago)
- Language: JavaScript
- Size: 155 KB
- Stars: 20
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-lens-protocol - lens-create-publication-example - An example project showing how to create a publication using withSig and typed data. (Learn / Examples)
README
# Posting to Lens
This is an example project that shows how to:
1. Authenticate a user with the Lens API
2. Once authenticated, publish a post to Lens using [typed data](https://eips.ethereum.org/EIPS/eip-712)The `api.js` file has most of the helper functions needed for creating a `withSig` transaction, the GraphQL API, and the GraphQL queries and mutations.
> For this project to run, you must configure the Infura project ID and project secret. Check out `.example.env.local` for guidance.
### Sending authenticated requests
Once authenticated, you will receive an access token.
Using this access token, you can send authenticated requests to the Lens API.
Using the Apollo GraphQL client, there are two ways to do this:
1. Manually passing in headers:
```javascript
const result = await client.mutate({
mutation: createPostTypedData,
variables: {
request,
},
context: {
headers: {
Authorization: `Bearer ${token}`
}
}
})
```2. Configuring an Apollo Link:
```javascript
import { ApolloClient, InMemoryCache, gql, createHttpLink } from '@apollo/client'
import { setContext } from '@apollo/client/link/context';const authLink = setContext((_, { headers }) => {
const token = window.localStorage.getItem('your-storage-key')
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : "",
}
}
})const httpLink = createHttpLink({
uri: API_URL
})export const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache()
})
```