Documentation
CI/CD Service

Deployment with Hardhat

Learn how to deploy your Hardhat project's contracts with BuildBear's CI/CD service.

Right now we only support deployments with Hardhat. Hardhat test support is coming soon.

Setup GitHub Actions

BuildBear's CI/CD system uses GitHub Actions. We encourage you to check out the official GitHub Actions documentation for more information. For the purposes of this quickstart, you'll only need to create a .github/workflows directory at the top-level of your repository. Workflows are YAML files that we'll put in this folder.

Workflow File

To get started with Hardhat you can add this to your workflow:

name: Deploy to BuildBear Sandbox
 
on: [push]
 
jobs:
  test:
    name: Deploy to BuildBear Sandbox
    runs-on: ubuntu-latest
 
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          submodules: recursive
 
      - name: Use Node.js 20.16.0
        uses: actions/setup-node@v1
        with:
          node-version: 20.16.0
 
      - name: Cache Node Modules
        id: cache-node-modules
        uses: actions/cache@v4
        with:
          path: "node_modules"
          key: node_modules-${{ hashFiles('package-lock.json') }}
 
      - name: Install dependencies
        if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: npm ci
 
      - name: Run BB Action CI
        uses: BuildBearLabs/[email protected]
        env:
          HARDHAT_IGNITION_CONFIRM_DEPLOYMENT: false
        with:
          network: |
            [
              {
                "chainId": 1
              }
            ]
          deploy-command: "npx hardhat ignition deploy ./ignition/modules/Auction.ts --network buildbear_ci"
          buildbear-token: ${{ secrets.BUILDBEAR_TOKEN }}
 
      - name: Run Tests
        run: npx hardhat test --network buildbear_ci

A few things to highlight in the BB Action CI:

  • At the time of writing, v1.0.0 is the current version of the action, please check the BB CI Action GitHub repo for the latest version.
  • On line 35 we set an environment variable to disable user confirmation of deployments. Because we're automating the deployment this prevents it from stopping on this step.
  • network is a list that can take multiple chain objects and their specified IDs.