Chopin

Quick Start

Starting a new project

To get started developing with Chopin Framework, create a new Next.js project.

npx create-next-app@latest

After, you complete the create-next-app flow, you can start developing using the command.

npm run dev

While running the dev server, your app will be available on port 3000 by default. Continue reading the next section to learn how to integrate Chopin Framework with this project.

Integrating with an existing project

To add Chopin Framework to an existing Next.js project, initialize the integration with the following command.

npx chopd init

Then, to run your Chopin app, run the following command.

npx chopd

This will make your Chopin app available on port 4000. Therefore, you can go to localhost:4000 to test and develop your app locally.

Now you are free to develop your app like a normal Next.js app, except you should access your app through port 4000 instead of 3000.

Note that you do not need to run both npm run dev and npx chopd at the same time. Just run npx chopd by itself after initializing.

For full details, read the CLI documentation.

Handling authentication

In order to use Chopin Framework's authentication features, you need to install the @chopinframework/next package.

npm install @chopinframework/next

Then, to get the address of the logged in user, simply use the following server-side function.

import { getAddress } from "@chopinframework/next";
 
const address = await getAddress();

For full details, read the authentication documentation.

Fetching, random numbers, and timestamps

Any non-deterministic function (e.g. fetch, crypto.randomBytes, Date.now()) executed on the server must be called using the oracle module in the @chopinframework/next package. In other words, do this for any function that will get different results if you run it multiple times. Most code will not need this, but the listed cases are the most common times where it is needed.

import { Oracle } from "@chopinframework/next";
 
// Fetch example
const result = await Oracle.fetch("https://example.com");
 
// Random number example
const randomNumber = await Oracle.random();
 
// Timestamp example
const timestamp = await Oracle.now();

In order to use the oracle module with an arbitrary non-deterministic value, you can use the Oracle.notarize function.

import { Oracle } from "@chopinframework/next";
 
const result = await Oracle.notarize(() => {
    return "Hello, world!";
});

For full details, read the oracle documentation.

Deployment

More information about deploying your Chopin app is coming soon.