Compile a Contract
After you create and compose a digital assets project, you install dependencies and compile the smart contract.
Install dependencies after you generate or import a project, and install them again whenever the project's package.json file changes. Compile the contract after dependencies are installed and whenever Solidity, TypeScript deployment scripts, or generated project sources change.
- Open the Contracts view in the Blockchain App Builder For Besu activity bar in Visual Studio Code.
- Select the generated or imported Hardhat project, and then open the Deploy/Execute form for that project. If more than one project is available, select the project from the Project list at the top of the form.
- Select the Deploy tab, and then select Install Dependencies. Wait while the dependencies are installed. If the installation fails, correct the reported error and then select Install Dependencies again.
For projects generated with the compose function, npm installs the standard Hardhat and OpenZeppelin dependencies and resolves the bundled Oracle Blockchain Platform plug-ins from local archives in the
.obp-bap/plugins/folder. Keep that folder in the project; thepackage.jsonfile references the plug-in archives by using localfile:dependencies. - After the dependencies are installed successfully, select Compile. . Wait while the contract is compiled. If compilation fails, correct the reported error and then select Compile again.
Hardhat writes compiled artifacts to the project's artifacts/ directory and uses the cache/ directory for compiler cache data. The extension uses the artifacts, together with Composer-generated manifests, to discover token and account ABIs for deploy, execute, wrapper API, and RPC proxy tooling.
After you compile the contract, you can configure an environment and then deploy and run the contract.
Troubleshooting Compilation Errors
| Message or Condition | Resolution |
|---|---|
Unable to run npm install |
Node.js or npm is unavailable to Visual Studio Code. Verify the Node.js and npm installation, and then restart Visual Studio Code. If Node.js is managed by nvm, open Visual Studio Code from a terminal so that it inherits the shell PATH variable. |
Unable to run Hardhat |
Dependencies might not be installed, or local Hardhat, npx, or npm cannot be found. Run Install Dependencies and verify Node.js is available to Visual Studio Code. |
| npm cannot find a local plug-in archive | Confirm that the .obp-bap/plugins/ folder still exists and contains the bundled .tgz files that are referenced by the package.json file. Regenerate the project if the plug-ins folder was removed.
|
HH1: You are not inside a Hardhat project |
Ensure that the correct imported or composed project is selected in the Project selector. The selected root must contain the hardhat.config.ts file.
|
| Contract artifact is missing | Run Compile from the project that owns the contract. Do not use an artifact from a different reference project or SDK standard. |
| Compile errors remain after a source change | Run Clean, and then run Compile, so that Hardhat rebuilds artifacts from the current sources. |