Unable to verify contract on Binance smart chain testnet (BSC testnet)

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

Error! Unable to generate Contract ByteCode and ABI
Found the following ContractName(s) in source code : Box
But we were unable to locate a matching bytecode (err_code_2)

Initially i am deploying box contract only.Then for deployment i am using hardhat plugin ,there is no error occurs on deployment but whenever i am trying to verify and publish code on binance network i am getting this kind of issue but it verified and publish on rinkeby etherscan successfully.
here with i am attaching error i got from bsc testnet and my hardhat config file for bsc
my hardhat config file:

// hardhat.config.js

const {mnemonic} = require('./secrets.json');

require("@nomiclabs/hardhat-ethers");

require('@openzeppelin/hardhat-upgrades');

/**

 * @type import('hardhat/config').HardhatUserConfig

 */

module.exports = {

  solidity: "0.7.0",

  networks: {

    testnet: {

      url: `https://data-seed-prebsc-1-s1.binance.org:8545`,

      accounts: {mnemonic: mnemonic},

      network_id: 97,

      confirmations: 10,

      timeoutBlocks: 200,

      skipDryRun: true

  }

  },

  

};

can anyone helpme to sort out this issue.

1 Like

Hi @Prabhakaran,

I don’t know if BSCscan supports proxy contracts. Though I assume you should be able to verify the Box implementation contract, the proxy and the ProxyAdmin but you may not be able to interact using BSCscan.

Do you want to share your contract address?

Hi @abcoathup thanks for the response and here is my proxy address of contract which i deployed in bscscan testnet
0xDb34D22e149d1E5eDDD230FbDECCab582BfF46aa

1 Like

Thanks @abcoathup , this one is working for me to deploy our contract ..and i deployed it too by following the steps you were given.
now i got conflict in the step of verifying our proxy code..but i can able to verify my implementation contract..
my proxy contract address:
0x5153FA6Db892542E14A4586Bde2287A5411E2906
implementation contract address:
0xE67c064Babf7c1A26d8759912BbC4e7bf9Eb1aa2 (i verified it already)(i found implementation address in Internal txns..)
and i tried another method to deploy and verify proxy code :
for that i used this code and and tried to deployed it on remix while deploying we have to give 3 parameters
Logic:address,
admin:address,
data:bytes
i dont know which address we have to give in these fields.can you please clarify about it ..herewith i am attaching screenshot.


and here is my code which i used to deploy and verify proxy contract manually on binance smart chain testnet(bscscan testnet)

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies in extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain`call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
      return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        return _functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        return _functionCallWithValue(target, data, value, errorMessage);
    }

    function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

abstract contract Proxy {
    /**
     * @dev Delegates the current call to `implementation`.
     * 
     * This function does not return to its internall call site, it will return directly to the external caller.
     */
    function _delegate(address implementation) internal {
        // solhint-disable-next-line no-inline-assembly
        assembly {
            // Copy msg.data. We take full control of memory in this inline assembly
            // block because it will not return to Solidity code. We overwrite the
            // Solidity scratch pad at memory position 0.
            calldatacopy(0, 0, calldatasize())

            // Call the implementation.
            // out and outsize are 0 because we don't know the size yet.
            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)

            // Copy the returned data.
            returndatacopy(0, 0, returndatasize())

            switch result
            // delegatecall returns 0 on error.
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }

    /**
     * @dev This is a virtual function that should be overriden so it returns the address to which the fallback function
     * and {_fallback} should delegate.
     */
    function _implementation() internal virtual view returns (address);

    /**
     * @dev Delegates the current call to the address returned by `_implementation()`.
     * 
     * This function does not return to its internall call site, it will return directly to the external caller.
     */
    function _fallback() internal {
        _beforeFallback();
        _delegate(_implementation());
    }

    /**
     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
     * function in the contract matches the call data.
     */
    fallback () payable external {
        _fallback();
    }

    /**
     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
     * is empty.
     */
    receive () payable external {
        _fallback();
    }

    /**
     * @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
     * call, or as part of the Solidity `fallback` or `receive` functions.
     * 
     * If overriden should call `super._beforeFallback()`.
     */
    function _beforeFallback() internal virtual {
    }
}


contract UpgradeableProxy is Proxy {
    /**
     * @dev Initializes the upgradeable proxy with an initial implementation specified by `_logic`.
     * 
     * If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded
     * function call, and allows initializating the storage of the proxy like a Solidity constructor.
     */
    constructor(address _logic, bytes memory _data) public payable {
        assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
        _setImplementation(_logic);
        if(_data.length > 0) {
            // solhint-disable-next-line avoid-low-level-calls
            (bool success,) = _logic.delegatecall(_data);
            require(success);
        }
    }

    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 private constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev Returns the current implementation address.
     */
    function _implementation() internal override view returns (address impl) {
        bytes32 slot = _IMPLEMENTATION_SLOT;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            impl := sload(slot)
        }
    }

    /**
     * @dev Upgrades the proxy to a new implementation.
     * 
     * Emits an {Upgraded} event.
     */
    function _upgradeTo(address newImplementation) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        require(Address.isContract(newImplementation), "UpgradeableProxy: new implementation is not a contract");

        bytes32 slot = _IMPLEMENTATION_SLOT;

        // solhint-disable-next-line no-inline-assembly
        assembly {
            sstore(slot, newImplementation)
        }
    }
}
contract TransparentUpgradeableProxy is UpgradeableProxy {
    /**
     * @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and
     * optionally initialized with `_data` as explained in {UpgradeableProxy-constructor}.
     */
    constructor(address _logic, address _admin, bytes memory _data) public payable UpgradeableProxy(_logic, _data) {
        assert(_ADMIN_SLOT == bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1));
        _setAdmin(_admin);
    }

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 private constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin.
     */
    modifier ifAdmin() {
        if (msg.sender == _admin()) {
            _;
        } else {
            _fallback();
        }
    }

    /**
     * @dev Returns the current admin.
     * 
     * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}.
     * 
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
     * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function admin() external ifAdmin returns (address) {
        return _admin();
    }

    /**
     * @dev Returns the current implementation.
     * 
     * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}.
     * 
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the
     * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
     */
    function implementation() external ifAdmin returns (address) {
        return _implementation();
    }

    /**
     * @dev Changes the admin of the proxy.
     * 
     * Emits an {AdminChanged} event.
     * 
     * NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.
     */
    function changeAdmin(address newAdmin) external ifAdmin {
        require(newAdmin != address(0), "TransparentUpgradeableProxy: new admin is the zero address");
        emit AdminChanged(_admin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev Upgrade the implementation of the proxy.
     * 
     * NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.
     */
    function upgradeTo(address newImplementation) external ifAdmin {
        _upgradeTo(newImplementation);
    }

    /**
     * @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified
     * by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the
     * proxied contract.
     * 
     * NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.
     */
    function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin {
        _upgradeTo(newImplementation);
        // solhint-disable-next-line avoid-low-level-calls
        (bool success,) = newImplementation.delegatecall(data);
        require(success);
    }

    /**
     * @dev Returns the current admin.
     */
    function _admin() internal view returns (address adm) {
        bytes32 slot = _ADMIN_SLOT;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            adm := sload(slot)
        }
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        bytes32 slot = _ADMIN_SLOT;

        // solhint-disable-next-line no-inline-assembly
        assembly {
            sstore(slot, newAdmin)
        }
    }

    /**
     * @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.
     */
    function _beforeFallback() internal override virtual {
        require(msg.sender != _admin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target");
        super._beforeFallback();
    }
}

contract BEP20UpgradeableProxy is TransparentUpgradeableProxy {

    constructor(address logic, address admin, bytes memory data) TransparentUpgradeableProxy(logic, admin, data) public {

    }

}

and i tryied to deploy this proxy code using openzeppelin hardhat plugin but it got some errors like:

Visibility for constructor is ignored. If you want the contract to be non-deployable, making it "abstract" is sufficient.

can you please help me to verify proxy contract on bscscan testnet.

1 Like

Hi @Prabhakaran,

I assume the Hardhat Etherscan plugin doesn’t support the Binance smart chain.

It also looks like https://testnet.bscscan.com/ doesn’t currently support proxy contracts: https://medium.com/etherscan-blog/and-finally-proxy-contract-support-on-etherscan-693e3da0714b

I tried using a flattened version of the proxy to verify but was unsuccessful: https://etherscan.io/address/0x343a1cae36b1ca047b24fc2780869dc2c1b84137#code

I have previously used this process, which describes the logic, admin and the data parameters in the constructor: Verify Upgrades Plugins proxy on Etherscan

Hi @abcoathup,
Thanks for the response,If hardhat not supports we have to use truffle only right for Binance,
then ,this link you mentioned in the above response is etherscans verified contract:

and I will gone through this steps once again:

1 Like

Hi @Prabhakaran,

I just went to try verifying again and found the proxy is now verified. I assume you did this?

I verified the implementation contract and marked my proxy as a proxy. Etherscan has proxy support on Binance smart chain.

I checked your upgradeable contract and marked the proxy as a proxy, so you can now interact via Etherscan.

1 Like

Hi @abcoathup i didn’t verified that proxy contracts ,but now the contracts are verified , i too used same proxy code which you mentioned above


but i am getting some error because of contructors we are using …
1 Like

Hi @Prabhakaran,

I assume someone else verified the proxy.

I am not sure what you mean? Can you share the errors. If this isn't related to verification, then I suggest creating a new topic.

1 Like

Hi @abcoathup this kind of error i am facing…

1 Like

Hi @Prabhakaran,

Is that error when verifying your implementation contract?

Make sure you set the appropriate Solidity compiler version.

Etherscan tries to work out what the constructor arguments were, but you will need to manually edit them. See how the text starts with Note: Unable to determine constructor arguments

1 Like

No @abcoathup this error occurs on verification of proxy contract code …
And i will double check the compiler version …

1 Like

Hi @Prabhakaran,

Is this still an issue? The proxy contract is verified.

Hi @abcoathup now proxy contract is verified on Bscscan testnet after changing constructor to initializable function.

1 Like

2 posts were split to a new topic: Sent bnb to wrong address and transaction fails

Hello. I try veryfy tree contract but unsuccessfully, I deployed both through the remix and through the truffle, but it was still an error, here is the last contract that was deployed from the truffle.

Verifying LordCoin@0x5e9f2882cfcbc7f3cebdbf2e4e545f6365720a09 Unable to locate ContractCode at 0x5e9f2882cfcbc7f3cebdbf2e4e545f6365720a09 Failed to verify 1 contract(s): LordCoin@0x5e9f2882cfcbc7f3cebdbf2e4e545f6365720a09

But testnet working

Help me please(

A post was split to a new topic: How can I make a proxy contract on BSC Test Net?

@abcoathup I cannot verify my contract in BSC

pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";

contract HyperPesa is ERC20 {
    constructor(uint256 initialSupply) public ERC20 ("HyperPesa", "HPESA"){
        _mint(msg.sender, initialSupply);
    }
}

My smart contract is:0x9427b655cc06d817c5874757b1fb59c1b2b34ae5
Help me verify it

hi bro, I’m getting this error while verifing the code on bsc testnet

Error! Unable to locate Contract Code at 0xa43ef36bac9aab2a3c0e2b6ff74fae8174b25d2aIs this a valid Contract Address?

can you please guide me bro

Hi, bro @Dineshkumar_R, This one is your contract address right https://testnet.bscscan.com/address/0xa43ef36bac9aab2a3c0e2b6ff74fae8174b25d2a
Would you please check optimization enabled while verifying the contract and let me know which editor you are using to deploy the contract?

1 Like