remix error while coding a smart contract - solidity

I'm coding a contract and deploy it but REMIX gives me an error at this line and I can't understand why.
Line below
constructor (
address _client,
uint _duration,
uint _premium,
uint _payoutValue,
string _cropLocation,
address _link,
uint256 _oraclePaymentAmount);
payable Ownable() public
ERROR MESSAGE
ParserError: Expected pragma, import directive or contract/interface/library/struct/enum/constant/function definition.
--> II Project.sol:72:1:
|
72 | constructor (
DO YOU KNOW WHAT IS WRONG WITH IT?

If you want to declare a function to should define it like this:
function Ownable() payable public{}

Related

ParserError: Function, variable, struct or modifier declaration expected(Truffle test)

I am currently learning solidity.
I have written the code as it appears in "Hands-On Smart Contract Development With Solidity and Ethereum" (O'Reilly/Japanese edition), but when I run TruffleTest, I get the following error
CompileError: project:/contracts/Fundraiser.sol:9:1: ParserError: Function, variable, struct or modifier declaration expected.
Here is the code.
https://github.com/okahijiki/fundraiser
I would appreciate any advice you can give me.
My library's version
Truffle
v5.5.31 (core: 5.5.31)/
Ganache v7.4.3/
Solidity v0.5.16 (solc-js)/
Node v16.15.1/
Web3.js v1.7.4
Here's the linked code:
pragma solidity >0.4.23 <0.7.0;
contract Fundraiser{
string public name;
constructor(string memory _name)public{
name = _name;
}
Count the number of opening braces - and the number of closing braces. You are correctly opening and closing the contract, but the constructor is missing its closing brace.
The solution is simple - close the constructor block with a brace as well.
contract Fundraiser{
string public name;
constructor(string memory _name)public{
name = _name;
} // closing the constructor here
}

Read contract variable with only interface definition

I'm playing ethernaut Level 3, the original contract is here: https://ethernaut.openzeppelin.com/level/0x4dF32584890A0026e56f7535d0f2C6486753624f
When consecutiveWins is bigger or equal to 10, the player wins:
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import '#openzeppelin/contracts/math/SafeMath.sol';
contract CoinFlip {
using SafeMath for uint256;
uint256 public consecutiveWins;
...
}
Now I want to read the consecutiveWins value in my contract, so I defined an interface:
interface CoinFlip {
uint256 public consecutiveWins;
function flip(bool _guess) external returns (bool);
}
But it is not allowed to have a variable in an interface, what should I do?
Solidity compiler will automatically generate getter functions for public variables, so what you need is replacing consecutiveWins variable in your interface with a getter function like this:
function consecutiveWins() public view returns (uint256);
You can read more about it in Solidity docs here.

Erorr after truffle compile in Erc721 openzeppelin contract

im doing step by step of this article and i had a problem on truffle compile part.
I've got this error in cmd:
Error parsing #openzeppelin/contracts/token/ERC721/ERC721.sol: ParsedContract.sol:51:72: ParserError: Expected '{' but got reserved keyword 'override'
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
^------^
my contract :
pragma solidity ^0.6.0;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/utils/Counters.sol";
contract Uniken is ERC721{
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
mapping(string => uint8) hashes;
constructor() public ERC721("Uniken", "Ukn") {
}
function awardItem(address recipient, string memory hash, string memory metadata)
public
returns (uint256)
{
require(hashes[hash] != 1);
hashes[hash] = 1;
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(recipient, newItemId);
_setTokenURI(newItemId, metadata);
return newItemId;
}
}
I'd be thankfull if anyone tell me whatis the problem?
It seems like it isn't seeing the ERC165 contract that ERC721 extends from. That function that it is getting stuck on should be overriding a function of the same name in ERC165, but the truffle compiler doesn't see a function named supportsInterface() in a class that ERC721 inherits from. So I would check to make sure everything imported in the ERC721 smart contract is in the right place in your folder structures, and that ERC721 is correctly inheriting ERC165.
After made some research , I was in truffle version 5.0 and update to the latest version of truffle -> v5.4.6, I am now able to compile

TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address" admin.transfer(address(this).balance);

function endSale() public {
require(msg.sender == admin);
require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));
admin.transfer(address(this).balance);
}
}
error line ---> admin.transfer(address(this).balance);
can someone help me with this thank you
Address literals have the type address instead of address payable. They can be converted to address payable by using an explicit conversion, e.g. payable(0xdCad3a6d3569DF655070DEd06cb7A1b2Ccd1D3AF).
Source: Solidity v0.8.0 Breaking Changes
What it means, is that since Solidity 0.8, address is not payable by default. And if you want to send it native currency, you need to cast it to payable first.
Example:
payable(admin).transfer(address(this).balance);

I need help in understanding the following code

In the following code I am getting the following error when I declare selfdestruct() function in this code.
Error is :
Invalid implicit conversion from address to address payable requested.
pragma solidity >=0.4.22 <0.6.0;
contract owned{
address owner;
constructor() public{
owner = msg.sender;
}
modifier onlyOwner{
require(owner == msg.sender);
_;
}
}
contract mortal is owned{
function close()public onlyOwner{
selfdestruct(owner);
}
}
Assuming you're using version 0.5.x of the Solidity compiler, selfdestruct accepts an address payable, but you're passing in an address.
You can fix this by just changing the type of owner:
address payable owner;
But your pragma directive is a crazy range... there's no way to make this code work with both 0.4.x and 0.5.x compilers. There were quite a few breaking changes between those versions (including this one).