Adding Contracts to a Flow Account
Adding Contracts to a Flow Account

Adding Contracts to a Flow Account

Adding Contracts to a Flow Account

In the Build for Web on Dapper tutorial, the contract has already been deployed and added to the Dapper Platform. However, if you want to deploy your own contracts, you will need to go through the following steps. We will use the MonsterMaker contract for the example, which you can deploy to your own address and use for your own dApp. These same steps apply for any contracts that you are deploying.

  1. Ensure that you have flow installed on your system. You can follow the instructions here.
  2. Create a public and private key pair for the desired flow environment (testnet/mainnet)
flow keys generate --network=testnet

This will generate a public/private key pair that will be used to create an account:

image

3. Sign in to flowport with your desired wallet. Flow port will allow you to create an account that you can use to deploy your contracts:

image

This will bring you to a dashboard display. Click on “Advanced” in the lower left:

image

4. Click on “Advanced” and then “Create New Account”

image

5. Paste your public key that was generated by flow in the terminal in the first field, and leave the other fields as defaults. Click Submit:

image

6. When the transaction completes, scroll to the events section and look for the flow.AccountCreated type. Copy the address value. This is the address of your account and will be needed to deploying the contract.

image

7. Next we will need to use flow to deploy the contract to our newly created account. Go back to the terminal, and create a directory you will use for the deployment (e.g. deploy-monster-maker). Switch to that directory and type flow init:

image

8. This will create a default flow.json file that we will use to configure the deployment. Open flow.json in an editor such as VSCode:

image

9. Add your contract to this directory. For this example we will add the MonsterMaker contract. Note that the addresses for the NonFungibleToken and the MetadataViews refer to testnet addresses, since that is where we are deploying to:

image

10. Add the contract to the config and a section called “testnet-account” as below, adding the address generated from the account in flowport from step #6, and the private key generated in step #2. Note that the values of the testnet-account all match the values that were used when creating the account in flowport:

image

11. In order to deploy the contract, some flow is required to cover the cost of the transaction, and you will need to transfer some flow to your newly created account. Go to the Balances page on flowport:

image

12. Click “Send” and paste in the address of you Account (the address generated in step #6):

image

13. Go back to your terminal and execute the command

flow project deploy --network=testnet
image

You should see the contract deployed successfully after a few seconds.

14. Validate the successful contract deployment by going to flow-view-source, and entering the account address:

image

You should see the contract deployed as below:

image

15. Go back to the Dapper Developer Dashboard and you can follow the steps outlined In the “Adding an App to Dapper Platform” Section to add your contract to your app.

👋