0

I write a simple contract , i can deploy it to ganache , but i need publish it to bnb testnet,

demo.sol:

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

contract demo {
    uint256 public data;

    function set(uint256 _data) public {
        data = _data;
    }

    function add() public {
        data++;
    }

    function get() public view returns (uint256) {
        return data;
    }
}

hardhat.config.ts

test: {
  chainId: 97,
  // url:"https://bsc-testnet.public.blastapi.io",
  // url:"https://bsc-testnet.publicnode.com",
  url: "https://bsc-testnet-dataseed.bnbchain.org",
  // url: "https://bsc-testnet.bnbchain.org",
  // url: "https://bsc-testnet-rpc.publicnode.com",
  accounts: ["0x ****"],
  timeout: 10000,
  gasPrice: 100,
},

when i use hardhat :

npx hardhat run ./scripts/deploy.ts --network test

I waited all night, and he kept showing: ,

hardhat:core:hre Creating provider for network test +4s

Can someone tell me some possible reasons

full hardhat.config.ts:

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import '@openzeppelin/hardhat-upgrades';
import "hardhat-abi-exporter";
import fs from "fs";
const privateKey = fs.readFileSync("./private.key", {
  encoding: "utf-8"
});
const config: HardhatUserConfig = {
  solidity: {
    compilers: [
      {
        version: "0.8.17",
        settings: {
          optimizer: {
            enabled: true,
            runs: 200,
          },
        },
      },
      {
        version: "0.6.6",
        settings: {
          optimizer: {
            enabled: true,
            runs: 200,
          },
        },
      },
      {
        version: "0.5.16",
        settings: {
          optimizer: {
            enabled: true,
            runs: 200,
          },
        },
      },
      {
        version: "0.4.18",
        settings: {
          optimizer: {
            enabled: true,
            runs: 200,
          },
        },
      }
    ]
  },
  gasReporter: {
    // enabled  : true,
    currency: 'CNY',
    gasPrice: 5,
  },
  networks: {
    dev: {
      chainId: 97,
      // url:"https://bsc-testnet.public.blastapi.io",
      // url:"https://bsc-testnet.publicnode.com",
      url: "https://bsc-testnet-dataseed.bnbchain.org",
      // url: "https://bsc-testnet.bnbchain.org",
      // url: "https://bsc-testnet-rpc.publicnode.com",
      accounts: ["0xf9b1d***0278e9d4674b2005911e0b2"],
      timeout: 10000
    },
    prod:{
      chainId:56,
      url: 'https://rpc.ankr.com/bsc',
      accounts:[privateKey],
    },
    local:{
      chainId: 1337,
      url: "http://127.0.0.1:8545",
      accounts:["0x0f4108bc3a3138acac0fd7****e3e57da929"],
      allowUnlimitedContractSize: true
    }
  },
  paths: {
    cache: "./runtime/cache",
    artifacts: "./runtime/artifacts"
  },
  etherscan: {
    apiKey: '****',
  },
  abiExporter: {
    path: './runtime/abi',
    runOnCompile: true,
    clear: true,
    flat: true,
    only: [
      "TPB",
      "TPBGame",
      "TPBMining",
      "TPBWithdraw",
      "demo"
    ]
  }
};

export default config;

7
  • --network dev if the network name is dev in hardhat config, Commented Nov 3 at 5:30
  • i am sorry ,I changed my post to make it easier to read, there is no problem here
    – 小灰灰
    Commented Nov 3 at 9:31
  • Can you share your full hardhat.config.ts file? Commented Nov 3 at 9:59
  • @SYEDASADKAZMI full config uploaded,thankyou
    – 小灰灰
    Commented Nov 3 at 12:26
  • Instead of the address, you should use the private key in the value of accounts field, like accounts: [privateKey]. Commented Nov 3 at 13:38

2 Answers 2

0

Try to increase the timeout value and check if the endpoint is available.

For nodes of high quality, you can check BSC endpoints by Chainstack. There are the Developer and Growth plans. You can start with the Developer one (free) for your tests.

P.S. I'm a Developer Advocate at Chainstack.

1
  • Thank you very much, the answer is so simple, is that the node does not work properly. I switched nodes very quickly.
    – 小灰灰
    Commented Nov 11 at 3:01
0

If you’ve already created the contract you can deploy to (BSC)testnet by using (IDE)remix and METAMASK. The time frame depends on you executing correctly.

2
  • I AM REALLY NOT GOOD WITH OPERATING ON BNB CHAIN THIS IS JUST A RECOMMENDATION 🤫 Commented Nov 7 at 12:06
  • OR WELL MAYBE YOU SHOWLD SAY NETWORK. Commented Nov 7 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.