KCC Documents
  • Quickstart
  • Overview
    • Introduction
    • Features
    • Our Goal
    • Consensus Engine
    • Marketing Guide
      • Requirements
      • KCC Official Website Resource
      • KCC Social Media Promotion
      • PR & Third-Party Marketing Support
  • Developers
    • Network Endpoints
    • Deploy Smart Contract
      • Using Hardhat
      • Using Remix
    • Verify Smart Contract
      • Using Hardhat
      • Using Foundry
      • Using Remix
    • Issue ERC20 Token
    • Deploy NFTs
      • Create A Foundry Project
      • Create Your ERC721 Contract
      • Add Metadata
    • Run a Node
      • Hardware & System Requirements
      • Install KCC
      • Run A Full Node
      • Run A Validator Node
        • Block Rewards
        • Apply For Running A Validator
        • Manager Account And Validator Account
        • Run A Validator
      • Troubleshooting
    • Explorer
    • Oracles
      • KCC Oracle
    • Bridge
    • Dev Toolkit
    • Data
      • Indexing and Querying
        • The Graph
        • Using KCC's hosted subgraph
    • Gas Revenue Program
      • Rules for Calculation of Gas Revenue
      • How to Join the KCC Gas Revenue Program
  • Individuals
    • Wallet
      • Supported Wallet
      • Tutorial on how to set up wallet
      • Mutisig Wallet
        • Create New Safe
        • Send KCS From Your Safe
        • Use A DApp With Your Safe
    • Network Configuration
      • Configure Value
      • Tutorial on how to config KCC network in Metamask
      • Tutorial on how to config KCC network in Chainlist
    • Bridge Assets
      • Bridge assets from others chains
      • KCC Bridge
      • Bridge assets form Exchange
    • Find a dApp
      • Add Your dAPP
    • KCS Token
      • Get KCS
      • Stake KCS
        • How to participate in KCS Staking
        • How to redeem staked KCS
        • How to check or claim staking rewards
  • FAQs
    • FAQs
      • General FAQs
      • KCS and Staking FAQs
      • Validator FAQs
  • Future Developments
    • Milestone
  • CONTACT US
    • Contact Us
  • Disclosure
    • Disclaimers
    • Risk Statement
    • Media Kit
Powered by GitBook
On this page
  • Prerequisites
  • Create A New Project With Forge
  • Add Configurations For KCC
  1. Developers
  2. Deploy NFTs

Create A Foundry Project

PreviousDeploy NFTsNextCreate Your ERC721 Contract

Last updated 2 years ago

Like hardhat and truffle, foundry is a development environment for Ethereum smart contracts. And it is becoming more and more popular. Likewise, you can use foundry for developing and deploying smart contracts for KCC.

Prerequisites

  • Install foundry

Foundry provides three command-line tools: forge, cast, and anvil. If you have successfully installed foundry, you can invoke any of those in your shell.

Create A New Project With Forge

Let's create a new project called "my-nft" with the forge command from foundry:

forge init my-nft

After executing the commands above, forge will create a directory named "my-nft". And there are several subdirectories and a file named "foundry.toml" in that directory:

my-nft/
├── foundry.toml
├── lib
│   └── forge-std
├── script
│   └── Counter.s.sol
├── src
│   └── Counter.sol
└── test
    └── Counter.t.sol

Add Configurations For KCC

You can add two profiles to your foundry project by appending the following lines to the end of your foundry.toml file:

[profile.kcc_main]
src = 'src'
out = 'out'
libs = ['lib']
# KCC has not implemented the London fork yet 
evm_version = 'berlin'
eth_rpc_url = 'https://rpc-mainnet.kcc.network'

[profile.kcc_testnet]
src = 'src'
out = 'out'
libs = ['lib']
# KCC has not implemented the London fork yet 
evm_version = 'berlin'
eth_rpc_url = 'https://rpc-testnet.kcc.network'

To test the configurations above, let's deploy the generated contract in the "Counter.sol" file to the KCC testnet:

FOUNDRY_PROFILE=kcc_testnet  \
        forge create --private-key=xxxxxxxxxxx \
        --legacy  Counter
  • Forge reads the profile's name from the environment variable "FOUNDRY_PROFILE".

  • You should replace `xxxxxxxxxxx` with your own private key.

    • BTW, foundry also supports several other wallets: Keystore, mnemonic, and even Ledger. And it is not wise to use a private key except in a test.

  • You must use the --legacy option because KCC has not implemented EIP1559 yet.

If everything goes well, forge will print out the address of the deployed contract and the transaction hash for the deployment.