@chim4us this is mostly likley an error in one of your functions. E.g you arguments ar swapped around or something. I have seen this error before and the reason for it was just this. Can i see your contract code just so i can debug for u
Here the code
Ulo.sol
pragma solidity ^0.8.0;
import "./Context.sol";
import "./IERC20Metadata.sol";
import "./IERC20.sol";
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
unchecked {
_approve(sender, _msgSender(), currentAllowance - amount);
}
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[sender] = senderBalance - amount;
}
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
_afterTokenTransfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
contract Ulor is ERC20{
constructor() public ERC20("ULOR","ULO"){
_mint(msg.sender,(500000000000) * (10 ** uint256(decimals() )));
}
function acceptpayment ()public payable {
}
}
IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
IERC20Metadata.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
Context.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
The contract compile on remix. But using truffle its showing the error. Please help me out. Have tried all possibilities
Hey @chim4us bear with me will 100% look into this for you my surface book broke and is away getting fixed at microsoft so im buying a new laptop today son can i code and do work in the meantime. This eve when i get home ill take your code onto my machine and get it working for you. Hope this is ok
What i can tell you in the meantime though is definitely in your contract snd not any of the openzepoelin ones so what yo7 should do is comment out everying up to the constructor and compile. Then if it compiles uncomment ine function at a time to locate the line which the error is on this way you may je able to fix it once you know exactly where it is
It still did not work out
Hey @chim4us
That seems to be a Truffle related issue.
Please run these two commands and post here the results:
truffle --version
node --version
Cheers,
Dani
Hi Dan-i Please see attach
Hey @chim4us
Please update truffle to the latest version, if the pkg is installed globally sudo npm i -g truffle
.
If the pkg is installed locally in your repo npm i truffle
.
Once done run truffle --version
to make sure its updated (version should be 5.3.14).
Keep me posted,
Dani
Thanks so much it worked.
So this means i have to be updating my truffle
Anyone elses computer poo its pants when they changed the default compiler version and recompile?
But then compiles successfully
Hey all,
I am running into an issue where I get the error:
truffle(develop)> let instance = await helloworld.deployed()
Uncaught ReferenceError: global is not defined
at evalmachine.:2:19
global isn’t defined. At first I was running into trouble getting things to compile because solc was the wrong version but i managed to figure that one out by myself.
already missing remix’s simplicity but excited to be playing with the big boy tools.
I’ve managed to get Visual studio and the required plugins installed but its definitively a bit tricky following Phillip on windows and then translating the subtle differences. Any pro tips for VScode on linux/chromebook are also appreciated
Hope this finds you well,
Ben
Hey @ImmMeta, hope you are ok.
It might be an issue on your truffle installation, you can try follow this guide:
Carlos Z
i try deploying the contract i made but it giving me an error pls what should i do
pragma solidity 0.7.5;
contract BSShareQ{
mapping(address => uint256)balance;
mapping(uint256 => uint256) public referralreward;
mapping(address => uint256) public userreferralbonus;
address public owner;
address payable public projectFee;
address payable public withdrawalFEE;
address payable public supportFEe;
uint256 public minimiuminvestedAmount;
uint256 public numberinvestors;
uint256 public deadline;
uint256 public goal;
uint256 public total_invested;
uint256 public total_withdrawn;
uint256 public total_investors;
uint256 public total_referral_bonus;
constructor(){
owner = msg.sender;
minimiuminvestedAmount = 6300000000000000;
projectFee = msg.sender;
withdrawalFEE = msg.sender;
supportFEe = msg.sender;
}
function deposit() public payable returns(uint256){
require(msg.value >= minimiuminvestedAmount);
balance[msg.sender] += msg.value;
return balance[msg.sender];
if(balance[msg.sender] == 0){
numberinvestors++;
}
balance[msg.sender] += msg.value;
supportFEe.transfer(msg.value * 5 / 100);
projectFee.transfer(msg.value * 3 / 100);
}
function withdraw(uint256 amount) public returns(uint256){
require(balance[msg.sender] >= amount);
require(block.timestamp >= block.timestamp + 2592000 seconds && msg.value = msg.value * 140 / 100);
balance[msg.sender] -= amount;
msg.sender.transfer(amount);
balance[msg.sender] = 0;
}
function getbalance() public view returns (uint256){
return address(this).balance;
}
function transfer(address reciever, uint256 amount) public {
require(balance[msg.sender] >= amount);
require(msg.sender != reciever);
require(owner == msg.sender );
uint256 previousSenderBalance = balance[msg.sender];
_transfer(msg.sender , reciever,amount);
assert(balance[msg.sender] == previousSenderBalance - amount);
}
function _transfer(address from, address to, uint256 amount) private{
balance[from] -= amount;
balance[to] += amount;
}
}`Preformatted text`
Hi guys, I would like to know how you solved the issue below after the truffle compile
command is used to compile the very first program shown in the video: https://academy.ivanontech.com/lessons/truffle-hello-world
Source file requires different compiler version (current compiler is
0.8.7+commit.e28d00a7.Emscripten.clang) - note that nightly builds are
considered to be strictly less than the released version
Notice that in this program the compiler solidity 0.8.0 is used, so I am using the same compiler that I verified with the command solc --version
, that gave me the output below:
$$ solc, the solidity compiler commandline interface
Version: 0.8.0+commit.c7dfd78e.Darwin.appleclang
and changed in the truffle-config.js
file too the version of my compiler
compilers: {
solc: {
version: "0.8.0", // 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"
// }
}
},
I also followed what is show in the contents of this article (https://medium.com/blockchangers/how-to-fix-your-truffle-and-solidity-versioning-with-npx-from-npm-51b5fcb0825f) but nothing changed from my end.
Any advise would be highly appreciated it.
hey @cgironda change the compiler verion in the truffle config to whatever the veriosn you sepecify in your contracts. try close vs code and your terminal and reopen if its your first time
Thanks for the advise @mcgrane5 but after using the truffle version
command I obtain the output below without any other change:
Truffle v5.4.10 (core: 5.4.10)
Solidity - 0.8.0 (solc-js)
Node v14.17.6
Web3.js v1.5.2
Until here everything seems to be working, however the issue below still appears:
Source file requires different compiler version (current compiler is
0.8.7+commit.e28d00a7.Emscripten.clang) - note that nightly builds are
considered to be strictly less than the released version
Yeah strange im now bot sure wjy that would be the case. You could try reinstalling truffle thats works sometimes for people. @thecil have you any ideas on how to fox this error
Hi @mcgrane5 thank you for your time checking what I wrote here. I erased everything to start from scratch. So I reinstalled Truffle and followed the same process:
After using the truffle version
command I got the output below:
Truffle v5.4.11 (core: 5.4.11)
Solidity v0.5.16 (solc-js)
Node v14.17.6
Web3.js v1.5.2
So after using the commands npm init
and Truffle init
I changed the version of the compiler in the truffle-config.js
file as shown below:
compilers: {
solc: {
version: "0.8.0", // 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"
// }
}
},
Then using the truffle version
command again I obtained:
Truffle v5.4.11 (core: 5.4.11)
Solidity - 0.8.0 (solc-js)
Node v14.17.6
Web3.js v1.5.2
Finally, after using the truffle compile
command I obtained the output below:
Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
✔ Downloading compiler. Attempt #1.
> Compiling ./contracts/Migrations.sol
> Artifacts written to /Users/home/Documents/projects/IvanOnTech/ESC_201/hello_world/build/contracts
> Compiled successfully using:
- solc: 0.8.0+commit.c7dfd78e.Emscripten.clang
However, the message below persists when I open my editor and hover the mouse over the line code: pragma solidity 0.8.0;
Source file requires different compiler version (current compiler is
0.8.7+commit.e28d00a7.Emscripten.clang) - note that nightly builds are
considered to be strictly less than the released version
Apparently I am using the compiler version 0.8.0 but according to the message above I am not.
On the other hand, when the line of code pragma solidity 0.8.0;
is changed by pragma solidity ^0.8.0;
the message below appears when I hover the mouse over the word pragma
:
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.
I was wondering if the syntax plays some role here, or if something else is happening.
Did you have guys (@mcgrane5, @thecil ) a similar problem before?.
Any help would be appreciate it!