Giter Site home page Giter Site logo

how_to_deploy_contract-basic's Introduction

How to deploy Contract on BSC testnet

1.Set up Truffle

npm install -g truffle

Make an empty repository, cd into it, then

truffle init

Install HDWalletProvider

npm install --save truffle-hdwallet-provider

2. Create your contract

In ./contracts create a new contract called HelloWorld.sol with the following code:

pragma solidity ^0.4.23;
contract HelloWorld {
    function sayHello() public pure returns(string){
        return(“hello world”);
    }
}

3. Deploy your contract

In ./migrations, create a deployment script specifically named 2_deploy_contracts.js with the following code:

var HelloWorld = artifacts.require(“HelloWorld”);
module.exports = function(deployer) {
    deployer.deploy(HelloWorld, “hello”);
    // Additional contracts can be deployed here
};

4. Configure BSC testnet network and the provider

const HDWalletProvider = require('@truffle/hdwallet-provider');
const path = require("path");
require('dotenv').config()

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
  contracts_build_directory: path.join(__dirname, "client/src/contracts"),
  networks: {
    develop: {
      port: 8545
    },
    testnet: {
      provider: () => new HDWalletProvider(process.env.MNEMONIC, `https://data-seed-prebsc-1-s1.binance.org:8545`),
      network_id: 97,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true
    },
    bsc: {
      provider: () => new HDWalletProvider(process.env.MNEMONIC, `https://bsc-dataseed1.binance.org`),
      network_id: 56,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true
    },
  }
};
truffle deploy --network ropsten

5. Access your deployed contract

truffle console --network testnet

6. Finally, invoke contract function and say hello!

HelloWorld.deployed().then(function(instance){return instance.sayHello()});Also, Read

how_to_deploy_contract-basic's People

Contributors

hopefulheart2020 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.