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: noPRIVATE_KEYrequired; Hardhat uses a default mnemonic forlocalhost)
3. Start Local Node and Deploy (Server-Wide)
Step 1: Start a persistent Hardhat node
In a terminal:test test test ... junk). Leave this terminal open.
Step 2: Deploy contracts to localhost
In a second terminal:PRIVATE_KEY in .env needed). The script deploys:
- SecuritizationNotarization
- SecuritizationToken
- SecuritizationPaymentRouter
- CreditToken
Step 3: Configure project root .env
In the project root (not inside contracts/), add or 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:- Use the same local node as above (one deploy per node, or one shared deploy for all orgs).
- Add a row to
organization_blockchain_deploymentsfor each organisation that should use this chain.
BlockchainRouterService.get_user_blockchain():
Ways to add the row:
- API:
POST /api/organizations/{id}/deploywith body includingdeployment_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_deploymentswith the values above. - Admin UI: If you have an org admin screen for “blockchain deployment”, enter the same addresses and RPC URL.
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 bynpm 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
- Contracts: contracts/README.md (in repo)
- Configuration: Configuration — Blockchain & Smart Contract
- Rolling credits: Rolling Credits Setup
- Demo wallets: Demo Blockchain Wallets