> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shieldhq.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Contract Deployment

> Deploy Shield contract to Base

# Contract Deployment

Deploy the Shield contract to Base network.

## Prerequisites

* Hardhat installed
* Base network configured
* Deployer wallet with ETH

## Configuration

Update `hardhat.config.ts`:

```typescript theme={null}
import { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';

const config: HardhatUserConfig = {
  solidity: '0.8.24',
  networks: {
    baseSepolia: {
      url: `https://base-sepolia.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`,
      accounts: [process.env.PRIVATE_KEY!],
    },
    baseMainnet: {
      url: `https://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`,
      accounts: [process.env.PRIVATE_KEY!],
    },
  },
  etherscan: {
    apiKey: {
      baseSepolia: process.env.BASESCAN_API_KEY!,
      baseMainnet: process.env.BASESCAN_API_KEY!,
    },
  },
};

export default config;
```

## Deployment Script

Create `scripts/deploy.ts`:

```typescript theme={null}
import { ethers } from 'hardhat';

async function main() {
  const [deployer] = await ethers.getSigners();
  console.log('Deploying with account:', deployer.address);

  const balance = await deployer.provider.getBalance(deployer.address);
  console.log('Balance:', ethers.formatEther(balance), 'ETH');

  const Shield = await ethers.getContractFactory('Shield');
  const shield = await Shield.deploy();

  await shield.waitForDeployment();

  const address = await shield.getAddress();
  console.log('Shield deployed to:', address);
  console.log('Network:', (await ethers.provider.getNetwork()).name);

  // Save deployment info
  const deploymentInfo = {
    address,
    network: (await ethers.provider.getNetwork()).name,
    timestamp: new Date().toISOString(),
    deployer: deployer.address,
  };

  const fs = require('fs');
  fs.writeFileSync(
    `deployments/${deploymentInfo.network}.json`,
    JSON.stringify(deploymentInfo, null, 2)
  );
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });
```

## Deploy to Testnet

```bash theme={null}
# Set environment variables
export PRIVATE_KEY=your_private_key
export ALCHEMY_API_KEY=your_alchemy_key

# Deploy
cd contracts
npx hardhat run scripts/deploy.ts --network baseSepolia
```

## Deploy to Mainnet

```bash theme={null}
# Double-check you're using mainnet
export PRIVATE_KEY=your_mainnet_private_key
export ALCHEMY_API_KEY=your_alchemy_key

# Deploy
cd contracts
npx hardhat run scripts/deploy.ts --network baseMainnet
```

## Verification

After deployment, verify on BaseScan:

```bash theme={null}
# Testnet
npx hardhat verify --network baseSepolia DEPLOYED_ADDRESS

# Mainnet
npx hardhat verify --network baseMainnet DEPLOYED_ADDRESS
```

## Deployment Checklist

* [ ] Contract tested locally
* [ ] Testnet deployment successful
* [ ] Contract verified on BaseScan
* [ ] Frontend updated with new address
* [ ] Documentation updated
* [ ] Monitored for first transactions

## Post-Deployment

Update frontend `.env`:

```env theme={null}
NEXT_PUBLIC_SHIELD_CONTRACT_BASE=0x...mainnet...
NEXT_PUBLIC_SHIELD_CONTRACT_BASE_SEPOLIA=0x...testnet...
```
