Add Contracts to a Flow Project
Add a Contract
To add a contract to your project, update the "contracts"
section of your flow.json
file.
Contracts are specified as key-value pairs, where the key is the contract name, and the value is the location of the Cadence source code.
For example, the configuration below will register the
contract Foo
from the FooContract.cdc
file.
_10{_10 "contracts": {_10 "Foo": "./cadence/contracts/FooContract.cdc"_10 }_10}
Define Contract Deployment Targets
Once a contract is added, it can then be assigned to one or more deployment targets.
A deployment target is an account to which the contract will be deployed. In a typical project, a contract has one deployment target per network (e.g. Emulator, Testnet, Mainnet).
Deployment targets are defined in the "deployments"
section of your flow.json
file.
Targets are grouped by their network, where each network is a mapping from target account to contract list. Multiple contracts can be deployed to the same target account.
For example, here's how we'd deploy contracts Foo
and Bar
to the account my-testnet-account
:
_11{_11 "contracts": {_11 "Foo": "./cadence/contracts/FooContract.cdc",_11 "Bar": "./cadence/contracts/BarContract.cdc"_11 },_11 "deployments": {_11 "testnet": {_11 "my-testnet-account": ["Foo", "Bar"]_11 }_11 }_11}