FNCY Chain
FNCY 2.0.2 (ENG)
FNCY 2.0.2 (ENG)
  • Introduction
  • Getting Started
  • Design
    • Structure
    • Three Main Sets of Participants
    • PoSA Consensus
    • Governance
    • Staking
    • Mining Reward
    • Gas Fee
    • Runtime Upgrade
    • Cross-Chain Bridge
    • Security
  • Build On FNCY Chain
    • RPC Endpoints
    • Testnet Faucet
    • Block Explorer
      • Token Listing
    • BEP20 Token
    • NFT
    • Validator Requirements
    • NFT Market
      • FNCY Marketplace
  • For Developers
    • JSON-RPC
    • FNCY Chain API
      • Wallet API
      • Transaction API
      • Blockchain API
    • Wallet
      • FNCY Wallet
      • Use MetaMask for FNCY Chain
      • SDK
        • Android
          • Install
          • Guide
            • Initialize
            • Create/Restore Wallet
            • Wallet Search
            • Execute SendCoin/Contract
            • Transaction Search
            • Other Features
          • Methods
          • Domain
          • ETC
        • iOS
          • Install
          • Guide
            • Initialize
            • Create/Restore Wallet
            • Wallet Search
            • Execute SendCoin/Contract
            • Transaction Search
            • Other Features
          • Methods
          • Domain
          • ETC
    • Smart Contract
      • Deployment
        • Truffle
        • Hardhat
        • Remix IDE
      • Verify Your Contract on FncyScan
    • Gasless Transaction
    • with FNCY
      • FNCY Login
      • GAME AUTH Login
  • Tokenomics
  • Ecosystem Partner
  • FNCY Governance Partner
Powered by GitBook
On this page
  • Deploying Smart Contract Using Truffle
  • Preparation
  • Project Setting
  • Writing Smart Contract
  • Deploying Smart Contract
  • Wrapping Up
  1. For Developers
  2. Smart Contract
  3. Deployment

Truffle

Deploying Smart Contract Using Truffle

In this guide, you'll learn how to deploy a smart contract using Truffle. Truffle is a popular framework for developing Ethereum smart contracts, providing powerful tools and features.

Preparation

Before you get started, you'll need to prepare:

  • You must have Node.js and npm installed.

  • You must have Truffle installed.

Project Setting

  1. Create a new directory for your project and navigate to it.

  2. Run the following command to initialize a new npm project.

npm init -y
  1. To install Truffle, run the following command.

npm install --save-dev truffle
  1. To initialize Truffle, run the following command and follow the prompts.

// Some codenpx truffle init

Writing Smart Contract

  1. Create a new file calledMyContract.solin the contracts directory.

  2. Write the smart contract code in Solidity. For example:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MyContract {
    // Write the smart contract code.
}

Deploying Smart Contract

  1. Create a new file called2_deploy_contract.jsin the migrations directory.

  2. Write a deployment script using Truffle's migration API.

const MyContract = artifacts.require("MyContract");

module.exports = function(deployer) {
    deployer.deploy(MyContract);
};
  1. Run the following command to perform the migration.

npx truffle migrate --network <network-name>

Replace<network-name>with the name of the actual network you want to deploy to. or example, this could beropsten, rinkeby, mainnet , etc.

  1. The script deploys the smart contract and outputs the address of the deployed contract to the console.

Wrapping Up

You have successfully deployed a smart contract using Truffle. Now you can call the deployed contract using the address.

PreviousDeploymentNextHardhat

For more information, visit.

Truffle's official website