Skip to main content
This guide covers running a local Hardhat blockchain for CreditNexus: server-wide use (single RPC + contracts) and optional organisation-specific routing via OrganizationBlockchainDeployment.

1. Overview

Code: contracts/README.md, contracts/scripts/deploy.js, app/services/blockchain_service.py, app/services/blockchain_router.py, app/services/organization_service.py

2. Prerequisites

  • Node.js and npm in contracts/
  • Project root .env (optional for localhost: no PRIVATE_KEY required; Hardhat uses a default mnemonic for localhost)

3. Start Local Node and Deploy (Server-Wide)

Step 1: Start a persistent Hardhat node

In a terminal:
The node runs at http://127.0.0.1:8545 and uses the default Hardhat mnemonic (test test test ... junk). Leave this terminal open.

Step 2: Deploy contracts to localhost

In a second terminal:
This uses the same mnemonic (no PRIVATE_KEY in .env needed). The script deploys:
  • SecuritizationNotarization
  • SecuritizationToken
  • SecuritizationPaymentRouter
  • CreditToken
It prints addresses. Example:

Step 3: Configure project root .env

In the project root (not inside contracts/), add or set:
Optional for rolling credits on-chain: set BLOCKCHAIN_DEPLOYER_PRIVATE_KEY to the first Hardhat account’s private key (printed when you run npm run node), so the server can call CreditToken mintCredits / updateCredits. If you omit it, credits are still stored in the DB but not registered on-chain.

4. Organisation-Specific Blockchain (Optional)

If you want the server to route certain users to a specific chain (e.g. the same local node) by organisation:
  1. Use the same local node as above (one deploy per node, or one shared deploy for all orgs).
  2. Add a row to organization_blockchain_deployments for each organisation that should use this chain.
Columns used by BlockchainRouterService.get_user_blockchain(): Ways to add the row:
  • API: POST /api/organizations/{id}/deploy with body including deployment_type, chain_id, rpc_url, notarization_contract, token_contract, payment_router_contract. (Requires implementation to accept these; current implementation may use stubs.)
  • DB: Insert directly into organization_blockchain_deployments with the values above.
  • Admin UI: If you have an org admin screen for “blockchain deployment”, enter the same addresses and RPC URL.
When a user has organization_id set and that org has a deployment row, the server uses this RPC and these contracts for that user (e.g. notarization, CreditToken). Otherwise it falls back to global X402_NETWORK_RPC_URL and contract addresses from .env.

5. Demo Wallets and Accounts

For demo users with wallet addresses and private keys on the same local node, see Demo Blockchain Wallets. Use the accounts printed by npm run node (address + private key) in DEMO_BLOCKCHAIN_ACCOUNTS and set DEMO_BLOCKCHAIN_RPC_URL=http://127.0.0.1:8545.

6. Scripts Reference


7. Troubleshooting


8. References