NillionNetwork / awesome-nillion

Curated list of examples, tools, contracts, and projects built with Nillion
12 stars 3 forks source link

[Hacktoberfest] Create a simple Blind app with npx create-nillion-app #2

Open crypblizz8 opened 2 weeks ago

crypblizz8 commented 2 weeks ago

Thank you for taking the time to be a part of Hacktoberfest 2024! πŸŽ‰ πŸ₯³ πŸŽ‰

We are looking for contributors for the Examples (Community) Section in Awesome Nillion.

🚨 First things first 🚨

Make sure you are registered at Hacktoberfest.

If you ever get stuck, feel free to ask any questions in our Github Discussion.

Quickstart Guide

...

CLI

  1. Star this repository
  2. Use the npm package in your terminal - npx @nillion/create-nillion-app and then follow the CLI instructions
  3. Follow the prompts and you should have your boilerplate setup -- ask for help if you ever get stuck: this sets up a Next.js app + Nada
  4. cd into your folder and run npm run dev to start your dev server + your app should appear on localhost:3000
  5. Run nillion-devnet in another terminal window
  6. Reload your Next.js app and you should be able to login, store a value and retrieve a value

Creating a Simple Nada app

Now let's get started with the magic of Nada! πŸ§™β€β™‚οΈ First, let's set it up our environment.

Now that our Python environment is ready, we will create a secret_addition Nada Program -- you may also follow along this section.

  1. Create a new file with touch src/secret_addition.py
  2. Copy and paste the Nada Program code:
from nada_dsl import *

def nada_main():

    party1 = Party(name="Party1")

    my_int1 = SecretInteger(Input(name="my_int1", party=party1))

    my_int2 = SecretInteger(Input(name="my_int2", party=party1))

    new_int = my_int1 + my_int2

    return [Output(new_int, "my_output", party1)]
  1. Add your program to nada-project.toml config file
[[programs]]
path = "src/secret_addition.py"
name = "secret_addition"
prime_size = 128
  1. nada build to build your program
  2. nada generate-test --test-name secret_addition_test secret_addition to generate tests
  3. nada run secret_addition_test to run the program
  4. nada test secret_addition_test to run the tests

Connecting the Next.js app <> Nada Program

  1. Upload your program from your nada/src/target/secret_addition.nada.bin
  2. Copy the programID and use it in the Compute section
  3. Copy the computeOutputID and use it in the Compute Output section
  4. Congratulations! You have run the Nada Program via your frontend πŸŽ‰

Wrapping up

  1. Host your github on a public repository
  2. Once you are finished, create a PR on this repo (awesome-nillion) to be added to the community page -- see this example + answer the questions from the example
  3. Congratulations on completing your Nillion Hacktoberfest Challenge πŸ₯³ πŸ™Œ πŸŽ‰

Other

Add other issues here.

abu0091 commented 3 days ago

lets try