JabirPapa
JabirPapa

Reputation: 11

`pragma solidity` is giving error, even though I added the latest version

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

contract BankAccount {
    uint private balance;

    // Deposit function: adds an amount to the balance
    function deposit(uint amount) public {
        balance += amount;
    }

    // Withdraw function: deducts an amount from the balance
    function withdraw(uint amount) public {
        require(amount <= balance, 'Insufficient balance');
        balance -= amount;
    }

    // View function to check balance
    function getBalance() public view returns (uint) {
        return balance;
    }

    // Pure function to calculate simple interest
    function calculateInterest(uint principal, uint rate, uint time) public pure returns (uint) {
        return (principal * rate * time) / 100;
    }
}

Here is my contract but when I tried to compile it, it shows:

Compiling .\contracts\BankAccount.sol

> Compilation warnings encountered:

    Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> project:/contracts/BankAccount.sol

,Warning: Source file does not specify required compiler version! Consider adding "pragma solidity ^0.8.21;"
--> project:/contracts/BankAccount.sol

Everything is up to date, there is nothing to compile.

i have tried all the pragma solidity version even 0.8.21 but still its even me the same result

Upvotes: 1

Views: 39

Answers (1)

Steven
Steven

Reputation: 141

I am not sure you didn't show the hardhat.config.ts file, but I think this is the solidity compiler version error. I mean solidity compiler version in hardhat.config.ts file should be the same as solidity version in the contract.

In your BankAccount contract file, you use the exact same version as specified in hardhat.config.ts.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

Your hardhat config file already has the correct version setting;

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.21",
    settings: {
      optimizer: {
        enabled: true,
        runs: 100,
      },
      // viaIR: true,
    },
  },
  networks: {
    sepolia: {},
    ...
    }
   ...
}

Upvotes: 2

Related Questions