Unable to verify contracts on Binance smart chain testnet

Hi, I am trying to verify and publish my contract on Binance smart chain (BSC testnet) but i am getting error as

 [**Compiler debug log:**
Error! Unable to generate Contract ByteCode and ABI **(General Exception, unable to get compiled [bytecode])**

Contract Address- 0x44c4226bCEF93Ae198399DDe3ccD6D8D0d1A2f31

[pragma solidity =0.5.16;

import '@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol';
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

contract Token1 is ERC20Detailed, ERC20 {
  constructor() ERC20Detailed('Token 1', 'TK1', 18) public {}
}

Contract Address- 0xEd95f222731E7948CBcde54E2D7793e1E7193BBb

pragma solidity =0.5.16;

import '@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol';
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

contract Token2 is ERC20Detailed, ERC20 {
constructor() ERC20Detailed('Token 2', 'TK2', 18) public {}
}

UniswapV2Factory
Contract Address- 0x7701F3f9dDa68111A85301B7618EC15947f13E91

pragma solidity =0.5.16;

import './interfaces/IUniswapV2Factory.sol';
import './UniswapV2Pair.sol';

contract UniswapV2Factory is IUniswapV2Factory {
    address public feeTo;
    address public feeToSetter;

    mapping(address => mapping(address => address)) public getPair;
    address[] public allPairs;

    event PairCreated(address indexed token0, address indexed token1, address pair, uint);

    constructor(address _feeToSetter) public {
        feeToSetter = _feeToSetter;
    }

    function allPairsLength() external view returns (uint) {
        return allPairs.length;
    }

    function createPair(address tokenA, address tokenB) external returns (address pair) {
        require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES');
        (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
        require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS');
        require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient
        bytes memory bytecode = type(UniswapV2Pair).creationCode;
        bytes32 salt = keccak256(abi.encodePacked(token0, token1));
        assembly {
            pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
        }
        IUniswapV2Pair(pair).initialize(token0, token1);
        getPair[token0][token1] = pair;
        getPair[token1][token0] = pair; // populate mapping in the reverse direction
        allPairs.push(pair);
        emit PairCreated(token0, token1, pair, allPairs.length);
    }

    function setFeeTo(address _feeTo) external {
        require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN');
        feeTo = _feeTo;
    }

    function setFeeToSetter(address _feeToSetter) external {
        require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN');
        feeToSetter = _feeToSetter;
    }
}

My Truffle config.js file

const HDWalletProvider = require('@truffle/hdwallet-provider');
const provider = new HDWalletProvider({
  privateKeys: ['1xxxxxxx465f56670d09aeb31da264a01xxxxxxx35bcb822183xxxx'],
  providerOrUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545/'
});

/**
 * Use this file to configure your truffle project. It's seeded with some
 * common settings for different networks and features like migrations,
 * compilation and testing. Uncomment the ones you need or modify
 * them to suit your project as necessary.
 *
 * More information about configuration can be found at:
 *
 * trufflesuite.com/docs/advanced/configuration
 *
 * To deploy via Infura you'll need a wallet provider (like @truffle/hdwallet-provider)
 * to sign your transactions before they're sent to a remote public node. Infura accounts
 * are available for free at: infura.io/register.
 *
 * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
 * public/private key pairs. If you're publishing your code to GitHub make sure you load this
 * phrase from a file you've .gitignored so it doesn't accidentally become public.
 *
 */

// const HDWalletProvider = require('@truffle/hdwallet-provider');
// const infuraKey = "fj4jll3k.....";
//
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  /**
   * Networks define how you connect to your ethereum client and let you set the
   * defaults web3 uses to send transactions. If you don't specify one truffle
   * will spin up a development blockchain for you on port 9545 when you
   * run `develop` or `test`. You can ask a truffle command to use a specific
   * network from the command line, e.g
   *
   * $ truffle test --network <network-name>
   */

  networks: {
    binanceTestnet: {
      provider: () => provider,
      network_id: "97",
      gas: 10000000
    },
    // Useful for testing. The `development` name is special - truffle uses it by default
    // if it's defined here and no other network is specified at the command line.
    // You should run a client (like ganache-cli, geth or parity) in a separate terminal
    // tab if you use this network and you must also set the `host`, `port` and `network_id`
    // options below to some value.
    //
    // development: {
    //  host: "127.0.0.1",     // Localhost (default: none)
    //  port: 8545,            // Standard Ethereum port (default: none)
    //  network_id: "*",       // Any network (default: none)
    // },
    // Another network with more advanced options...
    // advanced: {
    // port: 8777,             // Custom port
    // network_id: 1342,       // Custom network
    // gas: 8500000,           // Gas sent with each transaction (default: ~6700000)
    // gasPrice: 20000000000,  // 20 gwei (in wei) (default: 100 gwei)
    // from: <address>,        // Account to send txs from (default: accounts[0])
    // websockets: true        // Enable EventEmitter interface for web3 (default: false)
    // },
    // Useful for deploying to a public network.
    // NB: It's important to wrap the provider as a function.
    // ropsten: {
    // provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
    // network_id: 3,       // Ropsten's id
    // gas: 5500000,        // Ropsten has a lower block limit than mainnet
    // confirmations: 2,    // # of confs to wait between deployments. (default: 0)
    // timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
    // skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )
    // },
    // Useful for private networks
    // private: {
    // provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
    // network_id: 2111,   // This network is yours, in the cloud.
    // production: true    // Treats this network as if it was a public net. (default: false)
    // }
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.5.16",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    },
  },
};

Please anyone help

1 Like

Hi @Bsc_Talk,

For Ethereum mainnet and testnets I would recommend: Verify smart contract inheriting from OpenZeppelin Contracts

I don’t know if the verify plugins support Binance Smart Chain, so you may need to flatten your contract and encode the constructor parameters (https://abi.hashex.org/) via the block explorer.

i am getting error when i was trying to flatten i installed npm install truffle-flattener -g inside the folder

truffle-flattener ./contracts/input_Token1.sol > ./contracts/output_Token1.sol
(node:2886) Warning: Accessing non-existent property ‘INVALID_ALT_NUMBER’ of module exports inside circular dependency
(Use node --trace-warnings ... to show where the warning was created)
(node:2886) Warning: Accessing non-existent property ‘INVALID_ALT_NUMBER’ of module exports inside circular dependency
Error: None of the sub-resolvers resolved “contracts/input_Token1.sol” location.
at ResolverEngine. (/Users/rohankundu/.nvm/versions/node/v14.15.4/lib/node_modules/truffle-flattener/node_modules/@resolver-engine/core/build/src/resolverengine.js:35:23)
at Generator.next ()
at fulfilled (/Users/rohankundu/.nvm/versions/node/v14.15.4/lib/node_modules/truffle-flattener/node_modules/@resolver-engine/core/build/src/resolverengine.js:4:58)
at processTicksAndRejections (internal/process/task_queues.js:93:5)

1 Like

Hi @Bsc_Talk,

It looks like truffle-flattener couldn’t find ./contracts/input_Token1.sol. Can you check that path and name of the file are correct?

A post was split to a new topic: Verify contract on BSCscan: Error! Unable to generate Contract ByteCode and ABI