ParserError: Expected '{' but got '(' function stake() public payable () - ethereum

pragma solidity >=0.6.0 <0.7.0;
import "hardhat/console.sol";
import "./ExampleExternalContract.sol";
contract Staker {
ExampleExternalContract public exampleExternalContract;
mapping(address => uint256) public balances;
uint256 public constant treshold = 1 ether;
event Stake(address staker, uint256 amount);
constructor(address exampleExternalContractAddress) public {
exampleExternalContract = ExampleExternalContract(exampleExternalContractAddress);
}
function stake() public payable () {
balances[msg.sender] = msg.value;
emit Stake(msg.sender, msg.value);
}
}
I am getting a parse error Expected '{' but got '(', when I try to deploy this code. Any thoughts on what's going on?

You have an extra pair of parentheses in the stake function definition.
Replace this
function stake() public payable () {
with this
function stake() public payable {

Related

How to fix undeclared identifier even though its present in ERC721Enumerable

I am trying to prepare a solidity smart contract and everything appears fine except a single undeclared error on remix compiler. The error code is as follows:
from solidity:
DeclarationError: Undeclared identifier.
--> contracts/WTest.sol:66:22:
|
66 | uint256 supply = totalSupply();
| ^^^^^^^^^^^
For reference, my code is as follows:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
import "#openzeppelin/contracts/utils/math/SafeMath.sol";
contract WTest is ERC721, ERC721Burnable, Ownable {
using Strings for uint256;
using SafeMath for uint256;
uint256 public mintPrice;
address public blackHoleAddress;
ERC721 public crateContract;
string public baseURI;
string public baseExtension = ".json";
mapping(uint256 => bool) private _crateProcessList;
bool public paused = false;
bool public revealed = false;
uint256 public maxSupply = 5000;
uint256 public maxPrivateSupply = 580;
uint256 public maxMintAmount = 20;
string public notRevealedUri;
event OperationResult(bool result, uint256 itemId);
constructor() ERC721("WTest", "WTST") {}
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
function setBASEURI(string memory newuri) public onlyOwner {
baseURI = newuri;
}
function setMintPrice(uint256 _mintPrice) public onlyOwner returns(bool success) {
mintPrice = _mintPrice;
return true;
}
function getMintPrice() public view returns (uint256)
{
return mintPrice;
}
function setBlackHoleAddress(address _blackHoleAddress) public onlyOwner returns(bool success) {
blackHoleAddress = _blackHoleAddress;
return true;
}
function setcrateContractAddress(ERC721 _crateContractAddress) public onlyOwner returns (bool success) {
crateContract = _crateContractAddress;
return true;
}
function mint(uint256 _mintAmount) public payable {
uint256 supply = totalSupply();
require(!paused);
require(_mintAmount > 0);
require(_mintAmount <= maxMintAmount);
require(supply + _mintAmount <= maxSupply);
if (msg.sender != owner()) {
require(msg.value >= mintPrice * _mintAmount);
}
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(msg.sender, supply + i);
}
}
As you can see I have referenced ERC721Enumerable.sol
Any help in understanding where I am going wrong would be greatly appreciated.
You must extend ERC721Enumerable, and only then you can use totalSupply() function.
Your smart contract should be similtar to this:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
import "#openzeppelin/contracts/utils/math/SafeMath.sol";
contract WTest is ERC721, ERC721Enumerable, ERC721Burnable, Ownable {
using Strings for uint256;
using SafeMath for uint256;
uint256 public mintPrice;
address public blackHoleAddress;
ERC721 public crateContract;
string public baseURI;
string public baseExtension = ".json";
mapping(uint256 => bool) private _crateProcessList;
bool public paused = false;
bool public revealed = false;
uint256 public maxSupply = 5000;
uint256 public maxPrivateSupply = 580;
uint256 public maxMintAmount = 20;
string public notRevealedUri;
event OperationResult(bool result, uint256 itemId);
constructor() ERC721("WTest", "WTST") {}
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
function setBASEURI(string memory newuri) public onlyOwner {
baseURI = newuri;
}
function setMintPrice(uint256 _mintPrice) public onlyOwner returns(bool success) {
mintPrice = _mintPrice;
return true;
}
function getMintPrice() public view returns (uint256)
{
return mintPrice;
}
function setBlackHoleAddress(address _blackHoleAddress) public onlyOwner returns(bool success) {
blackHoleAddress = _blackHoleAddress;
return true;
}
function setcrateContractAddress(ERC721 _crateContractAddress) public onlyOwner returns (bool success) {
crateContract = _crateContractAddress;
return true;
}
function mint(uint256 _mintAmount) public payable {
uint256 supply = totalSupply();
require(!paused);
require(_mintAmount > 0);
require(_mintAmount <= maxMintAmount);
require(supply + _mintAmount <= maxSupply);
if (msg.sender != owner()) {
require(msg.value >= mintPrice * _mintAmount);
}
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(msg.sender, supply + i);
}
}
// NOTE: Override ERC721Enumerable functions
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override(ERC721, ERC721Enumerable) {
super._beforeTokenTransfer(from, to, tokenId);
}
function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721Enumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}
}

How to Mint ERC1155 with my own ERC20 token

I'm tryin to mint my ERC1155 nfts with my own ERC20 so i did the following :
1- created a variable of ERC20
ERC20 public FCG = FCG<br>
and in the constructor i pass the address of the ERC20 token contract
FCG = ERC20(0x0fC5025C764cE34df352757e82f7B5c4Df39A836);
2- in my mint function i did the following code
function mintCharacterPublic(address to, uint256 id, uint256 amount) public payable returns(bool){
require(to != address(0), "ERC1155: mint to the zero address");
require(FCG.approve(address(this), MINT_PRICE), "can't approve your token");
require(uint256(FCG.allowance(msg.sender, address(this))) >= MINT_PRICE, "Not enough of tokens");
FCG.transferFrom(msg.sender, address(this), MINT_PRICE);
mintCharacter(to, id, amount);
_balances[id][to] +=amount;
return true;
}
but when i try to mint it does not apply and it throws "Not enough of tokens"
so i think that the approve function does not function correctly.
here is my smart contract for the token
// SPDX-License-Identifier: MIT
import "#openzeppelin/contracts/token/ERC20/ERC20.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
pragma solidity ^0.8.2;
contract Token {
mapping(address => uint) public balances;
mapping(address => mapping(address => uint)) public allowance;
uint public totalSupply = 1000000 * 10 ** 18;
string public name = "FightClub Token";
string public symbol = "FCT";
uint public decimals = 18;
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
constructor() {
balances[msg.sender] = totalSupply;
}
function balanceOf(address owner) public view returns(uint) {
return balances[owner];
}
function transfer(address to, uint value) public returns(bool) {
require(balanceOf(msg.sender) >= value, 'balance too low');
balances[to] += value;
balances[msg.sender] -= value;
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint value) public returns(bool) {
require(balanceOf(from) >= value, 'balance too low');
require(allowance[from][msg.sender] >= value, 'allowance too low');
balances[to] += value;
balances[from] -= value;
emit Transfer(from, to, value);
return true;
}
function approve(address spender, uint value) public returns (bool) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
}
This must be a two-step process:
The user authorizes your contract to spend the token.
The user calls mintCharacterPublic.
Your contract cannot grant itself permission to spend the originator's tokens. require(FCG.approve(address(this), MINT_PRICE), "can't approve your token"); means that the eip-721 contract sets its own approval to MINT_PRICE, not the end-user's.

Verifying solidity contract on polygonscan

I created a Solidity Contract. What information should go in "Enter the Solidity Contract Code below?"
Below I am also listing the solidity code I used.
I tried putting the code in directly and the website errors out on me.
I am also attaching the link to the contract on polygonscan
https://polygonscan.com/token/0xd1a8ee4c74e0153aa1282967336b4a35f60a8dab
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "#openzeppelin/contracts/access/Ownable.sol";
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
contract EmbassyBuddhas is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
uint256 public cost = 0.05 ether;
uint256 public presaleCost = 0.03 ether;
uint256 public maxSupply = 10000;
uint256 public maxMintAmount = 20;
bool public paused = false;
mapping(address => bool) public whitelisted;
mapping(address => bool) public presaleWallets;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
mint(msg.sender, 20);
}
// internal
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
// public
function mint(address _to, uint256 _mintAmount) public payable {
uint256 supply = totalSupply();
require(!paused);
require(_mintAmount > 0);
require(_mintAmount <= maxMintAmount);
require(supply + _mintAmount <= maxSupply);
if (msg.sender != owner()) {
if (whitelisted[msg.sender] != true) {
if (presaleWallets[msg.sender] != true) {
//general public
require(msg.value >= cost * _mintAmount);
} else {
//presale
require(msg.value >= presaleCost * _mintAmount);
}
}
}
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(_to, supply + i);
}
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).length > 0
? string(
abi.encodePacked(
currentBaseURI,
tokenId.toString(),
baseExtension
)
)
: "";
}
//only owner
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
function setPresaleCost(uint256 _newCost) public onlyOwner {
presaleCost = _newCost;
}
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension)
public
onlyOwner
{
baseExtension = _newBaseExtension;
}
function pause(bool _state) public onlyOwner {
paused = _state;
}
function whitelistUser(address _user) public onlyOwner {
whitelisted[_user] = true;
}
function removeWhitelistUser(address _user) public onlyOwner {
whitelisted[_user] = false;
}
function addPresaleUser(address _user) public onlyOwner {
presaleWallets[_user] = true;
}
function add100PresaleUsers(address[100] memory _users) public onlyOwner {
for (uint256 i = 0; i < 2; i++) {
presaleWallets[_users[i]] = true;
}
}
function removePresaleUser(address _user) public onlyOwner {
presaleWallets[_user] = false;
}
function withdraw() public payable onlyOwner {
(bool success, ) = payable(msg.sender).call{
value: address(this).balance
}("");
require(success);
}
}
if you are having problems verifying contract code is because in your contract you are importing code from others contract, but you are not pasting that code there, I'll recommend you to check how to "flatten" a contract in the tool you are using and paste the flattened contract there
I would prefer to use frameworks such as truffle and hardhat to verify the contract because it will help you to make it easy.
So you can read more details How to verify contract on this link

Error: Returned error: VM Exception while processing transaction: revert when creating with New

I'm using Drizzle and when ever I call createInvestorToken on this contract I get Error: Returned error: VM Exception while processing transaction: revert . Not sure how to debug this. It succeeds in the test, but it won't succeed otherwise.
If I remove the allTokens.push(new InvestmentToken(_name,_symbol,initalSupply,_cost)); it works.
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.21 <0.7.0;
import "#openzeppelin/contracts/token/ERC20/ERC20.sol";
contract InvestmentToken is ERC20{
string public name;
string public symbol;
uint256 public decimals = 0;
uint256 public INITIAL_SUPPLY;
uint256 public cost;
address public parent;
constructor(string memory _name, string memory _symbol, uint256 initalSupply, uint256 _cost) public {
name = _name;
symbol = _symbol;
INITIAL_SUPPLY = initalSupply;
cost=_cost;
parent = msg.sender;
_mint(msg.sender, INITIAL_SUPPLY);
}
function buyToken(address receiver, uint256 amount) public {
if (msg.sender != parent) {
revert("You may only buy through the DPAC token");
}
uint256 tokensLeft = balanceOf(msg.sender);
if (tokensLeft >= amount/cost){
_transfer(msg.sender,receiver, amount/cost);
} else {
revert("There are no more tokens");
}
}
}
contract TheParentToken {
string public name = "DPAC_Token";
string public symbol = "DPAC";
uint256 public decimals = 0;
uint256 public INITIAL_SUPPLY = 10000;
uint256 public numberOfTokens = 0;
mapping(address => bool) public tokenWhiteList;
InvestmentToken[] public allTokens;
address public administrator;
constructor() public {
administrator = msg.sender;
allTokens.push(new InvestmentToken("A","B",1000,1));
allTokens.push(new InvestmentToken("B","C",1000,1));
numberOfTokens = allTokens.length;
}
function createInvestorToken(string memory _name, string memory _symbol, uint256 initalSupply, uint256 _cost) public {
allTokens.push(new InvestmentToken(_name,_symbol,initalSupply,_cost));
numberOfTokens = allTokens.length;
}
function addTokenToWhiteList(address newToken) public {
if(msg.sender != administrator){
revert("Not Admin");
}
tokenWhiteList[newToken]=true;
}
function removeTokenFromWhiteList(address newToken) public {
if(msg.sender != administrator){
revert("Not Admin");
}
tokenWhiteList[newToken]=false;
}
}
In this case the token was hitting the gas limit, and the error wasn't being displayed as the Gas Issue.
I think because it was creating a token the error is suppressed.

Solidity ParserError: Expected identifier but got '('

Keep getting an error by my constructor
pragma solidity ^0.6.9;
contract Confrence{
address public organizer;
mapping (address => uint) public registrantsPaid;
uint public numRegisrants;
uint public quota;
//so you can log these events
event Deposit(address _from, uint _amount);
event Refund(address _to, uint _amount);
Confrence() public {//consturctor
organizer = msg.sender;
quota = 500;
numRegistrants = 0;
}
}
Is it that I need to put parameters in the parenthesis?