🏗️Build your first dApp with plurality


Plurality is currently in beta. Please do not use it in production.

We will create our first dApp that uses Plurality using React framework with typescript.

Want to jump directly to code? Checkout final code on Git

  1. Create a react project with Typescript

npx create-react-app plurality-dapp --template typescript
  1. Open the folder plurality-dapp in your editor of choice

  2. Install the plurality widget using the following command

npm i plurality-social-connect
  1. Go to src/ folder and create a new file declaration.d.ts with the following single line (Note: this step would resolve once a new package update with types comes out):

declare module 'plurality-social-connect';
  1. Now open App.tsx file and replace the contents with the following code block

import PluralitySocialConnect from 'plurality-social-connect';
import { useRef } from 'react';

const App = () => {
    const childRef: any = useRef(null);
    // Profile data handle
    const handleProfileDataReturned = (data) => {
        const receivedData = JSON.parse(JSON.stringify(data))
        console.log("Get profile data:", receivedData);

    return (
                options={{ apps: 'facebook,twitter' }}
                // all customization params are optional
                // customization={{ height: '200px', width: '500px', initialBackgroundColor: '#E8A123', initialTextColor: '#FFFFFF', flipBackgroundColor: '#12AE83', flipTextColor: '#FFFFFF'}}
export default App;
  1. Now run the demo with the following command

npm install && npm start

You should see a big pink button. Clicking on it will open the widget with the required workflows. If the user completes the workflow, their data will be received in the handleDataReturned event function.

Last updated