Contract Deployment

View as Markdown

Smart contracts live at packages/blockchain/contracts/*.sol and are deployed with Hardhat. Three target networks are pre-configured:

Network--network flagChain IDUse
Locallocalhost31337npx hardhat node (in packages/blockchain/)
Testnetadi_testnet99999Public ADI testnet (https://rpc.ab.testnet.adifoundation.ai/)
Mainnetadi_mainnet8400Production ADI mainnet

14.7.1 Deploy commands

$cd packages/blockchain
$
$# 1. Compile
$npx hardhat compile
$
$# 2. Deploy to local node
$npx hardhat node & # in another terminal
$npx hardhat run scripts/deploy.ts --network localhost
$
$# 3. Deploy to testnet
$PRIVATE_KEY=<deployer-pk> \
>ADI_TESTNET_RPC=https://rpc.ab.testnet.adifoundation.ai/ \
>npx hardhat run scripts/deploy.ts --network adi_testnet
$
$# 4. Deploy to mainnet
$PRIVATE_KEY=<deployer-pk> \
>ADI_MAINNET_RPC=https://rpc.ab.mainnet.adifoundation.ai/ \
>npx hardhat run scripts/deploy.ts --network adi_mainnet

The deploy script writes the deployed addresses to deployments/<network>.json. Copy them into your API env (DID_REGISTRY_ADDRESS, SCHEMA_REGISTRY_ADDRESS, etc.) before restarting the API.

14.7.2 Post-deploy steps

  1. Verify contracts on the explorer (if the ADI explorer supports verification): npx hardhat verify --network adi_testnet 0xAddr <constructor-args>.
  2. Initialise registries — some registries require an initialize(adminAddress, ...) call after deployment. Confirm in scripts/deploy.ts that this is run automatically. 3. Update API env with all five addresses.
  3. Run a smoke test: curl https://adid.dev/api/v1/dids after restart should return 200.

14.7.3 Upgrade strategy

The contracts use OpenZeppelin’s ReentrancyGuard and access-control patterns; they are not UUPS-upgradeable in the current revision. Upgrades require a redeploy + data migration. Plan:

  1. Deploy v2 contracts.
  2. Migrate state via custom script (read events, replay into new registry).
  3. Update API env atomically.
  4. Sunset v1 by removing API references; chain state remains historically queryable.

VERIFY: confirm no proxy pattern is in use.