Starting Example

Start building with Portrait


Let's say you are building a decentralized social network that allows users to create and share posts. Although Ethereum addresses are the primary identifiers, you are using decentralized domains to abstract away the complexity of Ethereum addresses.
But, why stop there? Web3 goes beyond the limitations of Web2. In addition to decentralized domains to improve the user experience, you are also able to pre-populate a user profile with a few lines of code, leveraging the open Portrait Protocol.
In this example, we will fetch a user's Portrait data and feed it into OpenAI to generate a profile bio for a new user of your decentralized social network.

Fetching a user's Portrait data

To fetch a Portrait from the Portrait Protocol, you can use the getPortrait function. This function takes in an Identity parameter, which can be either an Ethereum address, ENS name, or Collective Portrait name. The function will return a PortraitObject, which contains the user's Portrait data.
In the example below, we fetch the data from vitalik.eth.
import { Portrait } from 'portrait-sdk'
const portrait = new Portrait();
const portraitData = await portrait.getPortrait('vitalik.eth');
portraitData will hold all Portrait data of vitalik.eth. We can use this data to generate a biography through OpenAI.

Manipulating the Portrait data

Now that we have fetched data from a Portrait, we can manipulate the data according to our needs. In this example, we are simply feeding the portraitData object into the OpenAI API.
import { Portrait } from 'portrait-sdk'
import { Configuration, OpenAIApi } from 'openai';
const portrait = new Portrait();
const portraitData = await portrait.getPortrait('vitalik.eth');
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
const openai = new OpenAIApi(configuration);
const biography = await openai.createEdit({
model: 'text-davinci-edit-001',
input: portraitData,
instruction: 'Write a biography for a decentralized network with a max length of 100 characters.',
Note that the code above is showcasing an example. Further development and tweaking for OpenAI might be needed to get this code running correctly.