Starting Example
Start building with Portrait
Introduction
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.
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.
Note that the code above is showcasing an example. Further development and tweaking for OpenAI might be needed to get this code running correctly.
Last updated