Hardhat Test – Fixing Verification Failed Issues

contract-verificationhardhat

I have Error in plugin @nomiclabs/hardhat-etherscan: The selected network is hardhat. Please select a network supported by Etherscan. when trying to verify a contract in hardhat.

The contract: TestHardToken.sol

// It will be used by the Solidity compiler to validate its version.

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


// This is the main building block for smart contracts.
contract TestHardToken {
    // Some string type variables to identify the token.
    // The `public` modifier makes a variable readable from outside the contract.
    string public name = "TestHHtoken";
    string public symbol = "THHT";

    // The fixed amount of tokens stored in an unsigned integer type variable.
    uint256 public totalSupply = 1000000;

    // An address type variable is used to store ethereum accounts.
    address public owner;

    // A mapping is a key/value map. Here we store each account balance.
    mapping(address => uint256) balances;

    /**
     * Contract initialization.
     *
     * The `constructor` is executed only once when the contract is created.
     */
    constructor() {
        // The totalSupply is assigned to transaction sender, which is the account
        // that is deploying the contract.
        balances[msg.sender] = totalSupply;
        owner = msg.sender;
    }

    /**
     * A function to transfer tokens.
     *
     * The `external` modifier makes a function *only* callable from outside
     * the contract.
     */
    function transfer(address to, uint256 amount) external {
        // Check if the transaction sender has enough tokens.
        // If `require`'s first argument evaluates to `false` then the
        // transaction will revert.
        require(balances[msg.sender] >= amount, "Not enough tokens");

        // Transfer the amount.
        balances[msg.sender] -= amount;
        balances[to] += amount;
    }

    /**
     * Read only function to retrieve the token balance of a given account.
     *
     * The `view` modifier indicates that it doesn't modify the contract's
     * state, which allows us to call it without executing a transaction.
     */
    function balanceOf(address account) external view returns (uint256) {
        return balances[account];
    }
} 

The console:


PS C:DEV\HardHat_training> npx hardhat compile
PS C:DEV\HardHat_training> npx hardhat run scripts/deploy.js --network fantomtestnet
Deploying contracts with the account: 0xf1a2d1217d2Fb0aB9E6236951B55545762cd8Ec4
Account balance: 69569568464648000000
Token address: 0xA85A868EB7B580eb2B4cC1b10d8a4d2133808258
PS C:DEV\HardHat_training> npx hardhat clean
PS C:DEV\HardHat_training> npx hardhat verify --network fantomtestnet  0xA85A868EB7B580eb2B4cC1b10d8a4d2133808258
Compiled 1 Solidity file successfully
Successfully submitted source code for contract
contracts/TestHardToken.sol:TestHardToken at 0xA85A868EB7B580eb2B4cC1b10d8a4d2133808258
for verification on the block explorer. Waiting for verification result...

We tried verifying your contract TestHardToken without including any unrelated one, but it failed.
Trying again with the full solc input used to compile and deploy it.
This means that unrelated contracts may be displayed on Etherscan...

Successfully submitted source code for contract
contracts/TestHardToken.sol:TestHardToken at 0xA85A868EB7B580eb2B4cC1b10d8a4d2133808258
for verification on the block explorer. Waiting for verification result...

Error in plugin @nomiclabs/hardhat-etherscan: The contract verification failed.
Reason: Fail - Unable to verify

For more info run Hardhat with --show-stack-traces

Best Answer

Solved It wasn't me https://testnet.ftmscan.com/ was working funny, I verify at first attempt at mainnet :( unlucky I guess