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

Keep release up to date with main #11

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
## Description

_Concise description of proposed changes, We recommend using screenshots and videos for better description_
Please add a concise description of proposed changes, We recommend using screenshots and videos for better description

## Additional Information

- [ ] I have read the [contributing docs](/scaffold-eth/scaffold-eth-2/blob/main/CONTRIBUTING.md) (if this is your first contribution)
- [ ] This is not a duplicate of any [existing pull request](https://github.com/scaffold-eth/scaffold-eth-2/pulls)
- [ ] I have read the [contributing docs](/NillionNetwork/scaffold-nillion/blob/main/CONTRIBUTING.md) (if this is your first contribution)
- [ ] This is not a duplicate of any [existing pull request](https://github.com/NillionNetwork/scaffold-nillion/pulls)

## Related Issues

_Closes #{issue number}_

_Note: If your changes are small and straightforward, you may skip the creation of an issue beforehand and remove this section. However, for medium-to-large changes, it is recommended to have an open issue for discussion and approval prior to submitting a pull request._

Your ENS/address:
Optional - Your ENS/address:
7 changes: 2 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ We follow the ["fork-and-pull" Git workflow](https://github.com/susam/gitpr)
3. Create a new branch with a descriptive name
4. Commit your changes to the new branch
5. Push changes to your fork
6. Open a PR in our repository and tag one of the maintainers to review your PR
6. Open a PR in our repository by [creating a pull request from your fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork). Use the "main" branch as the base branch, the branch in the repository that you want to merge your changes into.
7. Tag one of the maintainers to review your PR

Here are some tips for a high-quality pull request:

Expand All @@ -78,7 +79,3 @@ Once you submit your PR:
- As you update your PR and apply changes, mark each conversation resolved.

Once the PR is approved, we'll "squash-and-merge" to keep the git commit history clean.

The PR will either be
- merged into main, for bug fixes
- merged into release, to be merged in with the next release
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
5 changes: 5 additions & 0 deletions packages/hardhat/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
ALCHEMY_API_KEY=
DEPLOYER_PRIVATE_KEY=
ETHERSCAN_API_KEY=

# Auto populated by yarn nillion-devnet
NILLION_CONFIG_RPC_URL=
NILLION_CONFIG_DEPLOYER_PRIVATE_KEY=
NILLION_CONFIG_CHAIN_ID=
1 change: 1 addition & 0 deletions packages/hardhat/deployments/configNetwork/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
31337
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"address": "0x1314bf308272cf3BF20B4aAA62e973eCE6ADFbF8",
"address": "0xbdEd0D2bf404bdcBa897a74E6657f1f12e5C6fb6",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -139,24 +139,24 @@
"type": "receive"
}
],
"transactionHash": "0xf1c87a8f67f7b04286351cfc54c8f566a70d27ad976bb64da38cec1720bf7a09",
"transactionHash": "0x285371eb55d6c5aa5b223c7ab49aebc54dc197086f85da83ff02936234a1a750",
"receipt": {
"to": null,
"from": "0x19B4609b7DD591589D5475815f872bDa34B64755",
"contractAddress": "0x1314bf308272cf3BF20B4aAA62e973eCE6ADFbF8",
"from": "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65",
"contractAddress": "0xbdEd0D2bf404bdcBa897a74E6657f1f12e5C6fb6",
"transactionIndex": 0,
"gasUsed": "534699",
"gasUsed": "534867",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"blockHash": "0xf957fb0657fc23c43bcb92a461c67b9f496d101cbd65de169d8bfa45479b35de",
"transactionHash": "0xf1c87a8f67f7b04286351cfc54c8f566a70d27ad976bb64da38cec1720bf7a09",
"blockHash": "0xed735a5a97d07e7f2c6aa22002fdc4de57265826960eed1fd47ac754122ba73d",
"transactionHash": "0x285371eb55d6c5aa5b223c7ab49aebc54dc197086f85da83ff02936234a1a750",
"logs": [],
"blockNumber": 1323412,
"cumulativeGasUsed": "534699",
"blockNumber": 96,
"cumulativeGasUsed": "534867",
"status": 1,
"byzantium": true
},
"args": [
"0x19B4609b7DD591589D5475815f872bDa34B64755"
"0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65"
],
"numDeployments": 1,
"solcInputHash": "93c68bd44761a49b132fa5800b71769d",
Expand Down
1 change: 0 additions & 1 deletion packages/hardhat/deployments/nillionTestnet/.chainId

This file was deleted.

19 changes: 15 additions & 4 deletions packages/hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ const deployerPrivateKey =
// If not set, it uses ours Etherscan default API key.
const etherscanApiKey = process.env.ETHERSCAN_API_KEY || "DNXJA8RX2Q3VZ4URQIWP7Z68CJXQZSC6AW";

// Add any other testnet from config
const configNetwork =
process.env.NILLION_CONFIG_RPC_URL &&
process.env.NILLION_CONFIG_DEPLOYER_PRIVATE_KEY &&
process.env.NILLION_CONFIG_CHAIN_ID
? {
configNetwork: {
url: process.env.NILLION_CONFIG_RPC_URL,
accounts: [process.env.NILLION_CONFIG_DEPLOYER_PRIVATE_KEY],
chainId: parseInt(process.env.NILLION_CONFIG_CHAIN_ID),
},
}
: {};

const config: HardhatUserConfig = {
solidity: {
version: "0.8.17",
Expand Down Expand Up @@ -126,10 +140,7 @@ const config: HardhatUserConfig = {
url: "https://sepolia.publicgoods.network",
accounts: [deployerPrivateKey],
},
nillionTestnet: {
url: "https://rpc-endpoint.testnet-fe.nilogy.xyz",
accounts: [deployerPrivateKey],
},
...configNetwork,
},
// configuration for harhdat-verify plugin
etherscan: {
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.hardhat;

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
38 changes: 22 additions & 16 deletions packages/nillion/bootstrap-local-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ OUTFILE=$(mktemp);
PIDFILE=$(mktemp);

"$NILLION_DEVNET" --seed scaffold-nillion >"$OUTFILE" & echo $! >"$PIDFILE";
ENV_TO_UPDATE=".env ../nextjs/.env"
NEXTJS_ENV=".env ../nextjs/.env"
HARDHAT_ENV=".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 files with nillion-devnet environment info... This may take a minute."
echo "--------------------"
time_limit=160
while true; do
Expand Down Expand Up @@ -99,30 +100,35 @@ for ((i=1; i<=$num_node_keys; i++)); do
nodekey_file=$(mktemp)
"$NILLION_CLI" "$NILLION_CLI_COMMAND_NODE_KEYGEN" "$nodekey_file"
NODEKEY_FILES+=("$nodekey_file")
update_env "NEXT_PUBLIC_NILLION_NODEKEY_PATH_PARTY_$i" "$nodekey_file" $ENV_TO_UPDATE
update_env "NEXT_PUBLIC_NILLION_NODEKEY_TEXT_PARTY_$i" "$(log_file_contents $nodekey_file)" $ENV_TO_UPDATE
update_env "NEXT_PUBLIC_NILLION_NODEKEY_PATH_PARTY_$i" "$nodekey_file" $NEXTJS_ENV
update_env "NEXT_PUBLIC_NILLION_NODEKEY_TEXT_PARTY_$i" "$(log_file_contents $nodekey_file)" $NEXTJS_ENV
done

# Generate user keys and add to .env - ex: NEXT_PUBLIC_NILLION_USERKEY_PATH_PARTY_1
for ((i=1; i<=$num_user_keys; i++)); do
userkey_file=$(mktemp)
"$NILLION_CLI" "$NILLION_CLI_COMMAND_USER_KEYGEN" "$userkey_file"
USERKEY_FILES+=("$userkey_file")
update_env "NEXT_PUBLIC_NILLION_USERKEY_PATH_PARTY_$i" "$userkey_file" $ENV_TO_UPDATE
update_env "NEXT_PUBLIC_NILLION_USERKEY_TEXT_PARTY_$i" "$(log_file_contents $userkey_file)" $ENV_TO_UPDATE
update_env "NEXT_PUBLIC_NILLION_USERKEY_PATH_PARTY_$i" "$userkey_file" $NEXTJS_ENV
update_env "NEXT_PUBLIC_NILLION_USERKEY_TEXT_PARTY_$i" "$(log_file_contents $userkey_file)" $NEXTJS_ENV
done

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_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_BOOTNODE_MULTIADDRESS" "$BOOT_MULTIADDR" $ENV_TO_UPDATE
# Add environment variables to NextJs .env
update_env "NEXT_PUBLIC_NILLION_WEBSOCKETS" "$WEBSOCKET" $NEXTJS_ENV
update_env "NEXT_PUBLIC_NILLION_CLUSTER_ID" "$CLUSTER_ID" $NEXTJS_ENV
update_env "NEXT_PUBLIC_NILLION_BLOCKCHAIN_RPC_ENDPOINT" "$PAYMENTS_RPC" $NEXTJS_ENV
update_env "NEXT_PUBLIC_NILLION_BLINDING_FACTORS_MANAGER_SC_ADDRESS" "$PAYMENTS_BF_ADDR" $NEXTJS_ENV
update_env "NEXT_PUBLIC_NILLION_PAYMENTS_SC_ADDRESS" "$PAYMENTS_SC_ADDR" $NEXTJS_ENV
update_env "NEXT_PUBLIC_NILLION_CHAIN_ID" "$PAYMENTS_CHAIN" $NEXTJS_ENV
update_env "NEXT_PUBLIC_NILLION_WALLET_PRIVATE_KEY" "$WALLET_PRIVATE_KEY" $NEXTJS_ENV
update_env "NEXT_PUBLIC_NILLION_BOOTNODE_MULTIADDRESS" "$BOOT_MULTIADDR" $NEXTJS_ENV

# Add environment variables to Hardhat .env
update_env "NILLION_CONFIG_RPC_URL" "$PAYMENTS_RPC" $HARDHAT_ENV
update_env "NILLION_CONFIG_DEPLOYER_PRIVATE_KEY" "$WALLET_PRIVATE_KEY" $HARDHAT_ENV
update_env "NILLION_CONFIG_CHAIN_ID" "$PAYMENTS_CHAIN" $HARDHAT_ENV

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

Expand All @@ -141,5 +147,5 @@ echo "-------------------------------------------------------"
echo "-----------🦆 CONNECTED TO NILLION-DEVNET 🦆-----------"
echo "-------------------------------------------------------"

echo "ℹ️ Your $ENV_TO_UPDATE file configurations were updated with nillion-devnet connection variables: websocket, cluster id, keys, blockchain info"
echo "ℹ️ Your NextJS and Hardhat .env file configurations were updated with nillion-devnet connection variables: websocket, cluster id, keys, blockchain info"
echo "💻 The Nillion devnet is still running behind the scenes; to spin down the Nillion devnet at any time, run 'yarn nillion-devnet-stop'"
Loading