Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
remove config and reorder commands to run nillion-devnet first
Browse files Browse the repository at this point in the history
  • Loading branch information
oceans404 committed Apr 16, 2024
1 parent 4c129a6 commit 8a036bc
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 364 deletions.
30 changes: 10 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,30 @@ cd scaffold-eth-with-nillion
yarn install
```
### 2. Run a local ethereum network in the first terminal:
### 2. Run the Nillion devnet in the first terminal:
This bootstraps Nillion devnet, a local network of nodes and adds cluster info to your NextJS app .env file and blockchain info to your Hardhat .env file
```
yarn nillion-devnet
```
### 3. Run a local ethereum network in the second terminal:
```
yarn chain
```
This command starts a local Ethereum network using Hardhat. The network runs on your local machine and can be used for testing and development. You can customize the network configuration in `hardhat.config.ts`.
### 3. Open a second terminal and deploy the test ethereum contract:
### 4. Open a third terminal and deploy the test ethereum contract:
```
yarn deploy
```
This command deploys a test smart contract to the local network. The contract is located in `packages/hardhat/contracts` and can be modified to suit your needs. The `yarn deploy` command uses the deploy script located in `packages/hardhat/deploy` to deploy the contract to the network. You can also customize the deploy script.
### 4. Open a third terminal to run the Nillion devnet:
This bootstraps Nillion devnet, a local network of nodes and adds cluster info to your NextJS app .env file
```
yarn nillion-devnet
```
### 5. Optional: Nada program setup
If you want to write your own Nada programs, open another terminal to create and activate a python virtual environment
Expand Down Expand Up @@ -218,16 +218,6 @@ Run smart contract test with `yarn hardhat:test`
- Edit the code for this page in `packages/nextjs/app/nillion-hello-world/page.tsx` to complete each of the 🎯 TODOs to get the page working
- Need a hint on how to get something working? Take a look at the completed `packages/nextjs/app/nillion-hello-world-complete/page.tsx` page

## Connecting to Nillion Testnet

Today only Nucleus builders have been allowlisted to connect to the Nillion Testnet.

In step 4, `yarn nillion-devnet` sets up the scaffold to run a devnet (a local nillion network).

To instead connect to the Nillion Testnet, replace testnet values from `packages/nextjs/.env.nilliontestnet` with the devnet ones in your `packages/nextjs/.env`. Make sure that your `NEXT_PUBLIC_NILLION_NODEKEY_ALLOWLISTED_SEED` is one you shared with the Nillion team when allowlisting your peer id for the testnet.

Now when you run the NextJS app, your app will connect to the Nillion Testnet.

## About Scaffold-ETH 2

🧪 [Scaffold-ETH 2](https://docs.scaffoldeth.io) is an open-source, up-to-date toolkit for building decentralized applications (dapps) on the Ethereum blockchain. It's designed to make it easier for developers to create and deploy smart contracts and build user interfaces that interact with those contracts.
Expand Down
3 changes: 3 additions & 0 deletions packages/hardhat/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
ALCHEMY_API_KEY=
DEPLOYER_PRIVATE_KEY=
ETHERSCAN_API_KEY=

NEXT_PUBLIC_NILLION_BLOCKCHAIN_RPC_ENDPOINT=
NEXT_PUBLIC_NILLION_WALLET_PRIVATE_KEY=
1 change: 0 additions & 1 deletion packages/hardhat/deployments/nillionTestnet/.chainId

This file was deleted.

256 changes: 0 additions & 256 deletions packages/hardhat/deployments/nillionTestnet/YourContract.json

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions packages/hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ const config: HardhatUserConfig = {
url: "https://sepolia.publicgoods.network",
accounts: [deployerPrivateKey],
},
nillionTestnet: {
url: "https://rpc-endpoint.testnet-fe.nilogy.xyz",
accounts: [deployerPrivateKey],
configTestnet: {
url: process.env.NEXT_PUBLIC_NILLION_BLOCKCHAIN_RPC_ENDPOINT,
accounts: [process.env.NEXT_PUBLIC_NILLION_WALLET_PRIVATE_KEY || ""],
},
},
// configuration for harhdat-verify plugin
Expand Down
17 changes: 0 additions & 17 deletions packages/nextjs/.env.nilliontestnet

This file was deleted.

20 changes: 11 additions & 9 deletions packages/nextjs/components/nillion/RetrieveSecretCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ const RetrieveSecretCommand: React.FC<{
secretType: string;
}> = ({ userKey, storeId, secretName, secretType }) => {
return (
<span>
✅ Stored {secretType} {secretName} <br /> <CopyString str={storeId || ""} textBefore={`store_id: `} full />
<br />
<p>
👀 Optional: Copy and run the following command to retrieve-secret from the command line to see the value of{" "}
{secretName} using the nillion SDK tool
</p>
<CopyString str={retrieveSecretCommand(userKey, storeId, secretName)} start={30} end={30} code />
</span>
!process.env.NEXT_PUBLIC_USE_NILLION_CONFIG && (
<span>
✅ Stored {secretType} {secretName} <br /> <CopyString str={storeId || ""} textBefore={`store_id: `} full />
<br />
<p>
👀 Optional: Copy and run the following command to retrieve-secret from the command line to see the value of{" "}
{secretName} using the nillion SDK tool
</p>
<CopyString str={retrieveSecretCommand(userKey, storeId, secretName)} start={30} end={30} code />
</span>
)
);
};

Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract";

const deployedContracts = {
22255222: {
31337: {
YourContract: {
address: "0x1314bf308272cf3BF20B4aAA62e973eCE6ADFbF8",
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
abi: [
{
inputs: [
Expand Down
30 changes: 16 additions & 14 deletions packages/nextjs/scaffold.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ export type ScaffoldConfig = {
walletAutoConnect: boolean;
};

const nillionTestnet: chains.Chain = defineChain({
id: 22255222,
name: "Nillion Testnet",
network: "nillion-fe-testnet",
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
rpcUrls: {
default: { http: ["https://rpc-endpoint.testnet-fe.nilogy.xyz"] },
public: { http: ["https://rpc-endpoint.testnet-fe.nilogy.xyz"] },
},
const fallbackChain = chains.sepolia;

const rpcUrls = process.env.NEXT_PUBLIC_NILLION_BLOCKCHAIN_RPC_ENDPOINT
? {
default: { http: [process.env.NEXT_PUBLIC_NILLION_BLOCKCHAIN_RPC_ENDPOINT] },
public: { http: [process.env.NEXT_PUBLIC_NILLION_BLOCKCHAIN_RPC_ENDPOINT] },
}
: fallbackChain.rpcUrls;

const configChain: chains.Chain = defineChain({
...fallbackChain,
id: process.env.NEXT_PUBLIC_NILLION_CHAIN_ID ? parseInt(process.env.NEXT_PUBLIC_NILLION_CHAIN_ID) : fallbackChain.id,
name: process.env.NEXT_PUBLIC_NILLION_NAME || fallbackChain.name,
network: process.env.NEXT_PUBLIC_NILLION_NETWORK || fallbackChain.network,
rpcUrls,
});

const targetNetwork = process.env.NEXT_PUBLIC_USE_NILLION_TESTNET === "true" ? nillionTestnet : chains.hardhat;
const targetNetwork = process.env.NEXT_PUBLIC_USE_NILLION_CONFIG === "true" ? configChain : chains.hardhat;

const scaffoldConfig = {
// The networks on which your DApp is live
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/utils/scaffold-eth/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type IsContractDeclarationMissing<TYes, TNo> = typeof contractsData extends { [k

type ContractsDeclaration = IsContractDeclarationMissing<GenericContractsDeclaration, typeof contractsData>;

// @ts-ignore TODO remove ignore once Nillion Testnet chain id is added to viem
// @ts-ignore TODO remove ignore once chain id is added to viem
type Contracts = ContractsDeclaration[ConfiguredChainId];

export type ContractName = keyof Contracts;
Expand Down
7 changes: 4 additions & 3 deletions packages/nillion/bootstrap-local-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ PIDFILE=$(mktemp);

"$NILLION_DEVNET" --seed scaffold-nillion >"$OUTFILE" & echo $! >"$PIDFILE";
ENV_TO_UPDATE=".env ../nextjs/.env"
ENV_TO_UPDATE_WITH_HARDHAT=".env ../nextjs/.env ../hardhat/.env"
echo "--------------------"
echo "Updating your ${ENV_TO_UPDATE} files with nillion-devnet environment info... This may take a minute."
echo "Updating your ${ENV_TO_UPDATE_WITH_HARDHAT} files with nillion-devnet environment info... This may take a minute."
echo "--------------------"
time_limit=160
while true; do
Expand Down Expand Up @@ -117,11 +118,11 @@ echo "🔑 Node key and user keys have been generated and added to .env"
# Add environment variables to .env
update_env "NEXT_PUBLIC_NILLION_WEBSOCKETS" "$WEBSOCKET" $ENV_TO_UPDATE
update_env "NEXT_PUBLIC_NILLION_CLUSTER_ID" "$CLUSTER_ID" $ENV_TO_UPDATE
update_env "NEXT_PUBLIC_NILLION_BLOCKCHAIN_RPC_ENDPOINT" "$PAYMENTS_RPC" $ENV_TO_UPDATE
update_env "NEXT_PUBLIC_NILLION_BLOCKCHAIN_RPC_ENDPOINT" "$PAYMENTS_RPC" $ENV_TO_UPDATE_WITH_HARDHAT
update_env "NEXT_PUBLIC_NILLION_BLINDING_FACTORS_MANAGER_SC_ADDRESS" "$PAYMENTS_BF_ADDR" $ENV_TO_UPDATE
update_env "NEXT_PUBLIC_NILLION_PAYMENTS_SC_ADDRESS" "$PAYMENTS_SC_ADDR" $ENV_TO_UPDATE
update_env "NEXT_PUBLIC_NILLION_CHAIN_ID" "$PAYMENTS_CHAIN" $ENV_TO_UPDATE
update_env "NEXT_PUBLIC_NILLION_WALLET_PRIVATE_KEY" "$WALLET_PRIVATE_KEY" $ENV_TO_UPDATE
update_env "NEXT_PUBLIC_NILLION_WALLET_PRIVATE_KEY" "$WALLET_PRIVATE_KEY" $ENV_TO_UPDATE_WITH_HARDHAT
update_env "NEXT_PUBLIC_NILLION_BOOTNODE_MULTIADDRESS" "$BOOT_MULTIADDR" $ENV_TO_UPDATE

echo "Running at process pid: $(pgrep -f $NILLION_DEVNET)"
Expand Down

0 comments on commit 8a036bc

Please sign in to comment.