Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/animo/paradym-example-achievement-credential

This repository contains demo code that shows how to issue an achievement credential using a simple snake game as example.
https://github.com/animo/paradym-example-achievement-credential

Last synced: 3 days ago
JSON representation

This repository contains demo code that shows how to issue an achievement credential using a simple snake game as example.

Awesome Lists containing this project

README

        




screenshot-snake
screenshot-qr

Issue an achievement credential with Paradym

Easily integrate [Paradym](https://paradym.id) workflows into your existing application with this demo. This demo shows how Paradym can be used to issue an achievement credential using a simple snake game example.

This demo contains two packages: `client` and `server`. Both of these are located in the `/packages` directory. In order to get this demo to work, you will need to create two workflows and configure the environment variables in the `.env.example` file located `/packages/server` directory. To do so, follow the instructions below.

## Before you begin

> Check out the [YouTube video](https://www.youtube.com/watch?v=l_f6be1V-BU) for a complete walkthrough of the demo application and its workflows.

This demo uses [Paradym](https://paradym.id), a workflow builder for developers that provides the actions, workflows and infrastructure you need to use verifiable credentials in your solution.

If you don't have an account yet, you can start with our [quick start guide](https://docs.paradym.id/).

This demo also uses the [Paradym Wallet](https://docs.paradym.id/integrating-with-a-holder-wallet/paradym-wallet), an open source companion app to the Paradym platform available on the [Apple App Store](https://apps.apple.com/nl/app/paradym-wallet/id6449846111?l=en) and [Google Play Store](https://play.google.com/store/apps/details?id=id.paradym.wallet).

## Prerequisites

### Setup your workflows

The demo app requires 2 workflows. All workflows used for this demo application can be found in the `/paradym` folder.

- **Register Credential Template**: workflow used to register your credential schema and definition. The result of this workflow is used in the issuance workflow.
- **Issue High Score Badge**: workflow used to issue the achievement credential once the player beats the high score.

#### Step 1: Register your credential information

- Create a new workflow in Paradym with the name Register Credential Template.
- Copy the contents from `registerCredentialTemplate.yaml` into your created workflow.
- Publish the workflow.
- Execute the workflow via the executions tab.
- Click on the execution to view the result of your workflow.
- Copy the `credentialDefinitionId` from the result and save the value for later.

#### Step 2: Create the issue high score badge workflow

Next, you need to create the *Issue High Score Badge* workflow.

- Create new workflow in the Paradym dashboard
- Copy the contents of the `paradym/issueHighScoreBadge.yaml` file
- Replace the content of the newly created workflow with the value you just copied.
- Replace the `` values with the `credentialDefinitionId` value from step 1.
- Publish the workflow.

Once you have created the workflow in the Paradym dashboard, you can copy the workflow ID from Paradym and set it as the value for the `PARADYM_WORKFLOW_ID` environment variable in `packages/server/.env.example`.

#### Step 3: Create your Paradym API Key

You can generate your API key in the settings tab on the Paradym dashboard as described in [here](https://docs.paradym.id/executing-a-workflow/api-execution#api-key). Copy the API key and set it as the value for the `PARADYM_API_KEY` environment variable in `packages/server/.env.example`.

#### Step 4: Setup Paradym Webhook

The application uses Paradym Webhooks. For this, we need to create a Webhook in the Paradym dashboard (as described [here](https://docs.paradym.id/working-with-executions/using-webhooks)).

For this to work with your local environment, we'll need to expose port 3000 to the internet. This can be done using [ngrok](https://ngrok.com/). Once you have installed ngrok, you can run the following command to expose port 3000 to the internet.

```bash
ngrok http 3000
```

Use the **https** url to create your webhook in the Paradym dashboard. Make sure to add `/webhook` after the url (e.g. ).

After creating the webhook endpoint, copy the webhook secret and set it as the value for the `PARADYM_HMAC_SIGNATURE` in `packages/server/.env.example`.

> **NOTE:** Keep the ngrok server running and use a different terminal window for the following steps. If you restart the ngrok process, the URL will change and you have to reconfigure the webhook URL in paradym.

#### Step 5: Set the environment variables

The environment variables consist of your Paradym API Key, and the ID's of the workflows just created. Once you have created the workflows in the Paradym dashboard, you can copy the workflow ID's from Paradym and set them as environment variables.

```bash
cp packages/server/.env.example packages/server/.env
```

| Variable | Description |
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `PARADYM_API_KEY` | This is the API key used to send request to Paradym. You can generate your API key in the settings tab on the Paradym dashboard as described in [here](https://docs.paradym.id/executing-a-workflow/api-execution#api-key). |
| `PARADYM_WEBHOOK_SECRET` | This is a secret that is generated once you create a Webhook in the Paradym dashboard. You can set up a Webhook in the settings tab on the Paradym dashboard as described in [here](https://docs.paradym.id/working-with-executions/using-webhooks#setting-up-webhooks). |
| `PARADYM_WORKFLOW_ID` | This is the ID of the issue achievement credential workflow. Once you have created the workflow in Paradym you can copy the ID from the [executions tab](https://docs.paradym.id/executing-a-workflow/api-execution#workflow-id). | |

## Running the demo

Now you have created the workflows and configured the environment variables, the last thing you need to do before you can run the demo is install the dependencies for both the `client` and `server` packages.

```bash
cd packages/server
yarn
cd ../client
yarn
cd ../..
```

Now you need to start the development servers for both packages. Don't forget that

In your current terminal, run

```bash
cd packages/server
yarn dev
```

Open up a second terminal window, and run

```bash
cd packages/client
yarn dev
```

The last command will print a URL to the console. Copy and paste this URL into your browser to open up the snake game.