Expected identifier but got '(' in function - solidity

When I try to call CustomerFactory function I get
ParserError: Expected identifier but got '('
CustomerFactory(1,28);
I went over the documentation and I didn't see what I did wrong. Can someone advise?
pragma solidity ^0.7.0;
contract Manmade {
struct Customer {
uint customerID;
string nick;
}
Customer[] public customers;
function CustomerFactory(uint _customerID,string memory _nick)public{
customers.push(Customer(_customerID,_nick));
}
CustomerFactory(1,"Peter");
}

Your code CustomerFactory(1,"Peter"); is out of any function body which is not possible with solidity. Put this code into a function and it will work.

Related

Unable to compile smart contracts

I am learning the tutorials in 「Mastering Ethereum: Building Smart Contracts and DApps」(O'Reilly)
I copied the following sample code and created a solidity contract(METoken.sol).
Next, I compiled it with the「truffle compile」 command, but it gave me an error.Please assist, thanks
//Error Message
TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
// METoken.sol
pragma solidity ^0.4.21;
import 'openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol';
contract METoken is StandardToken {
string public constant name = 'Mastering Ethereum Token';
string public constant symbol = 'MET'; uint8 public constant decimals = 2; uint constant
_initial_supply = 2100000000;
function METoken() public {
totalSupply_ = _initial_supply;
balances[msg.sender] = _initial_supply;
emit Transfer(address(0), msg.sender, _initial_supply);
}
}
The Standard token was renamed to ERC20.sol in openzeppelin contracts 2.0 version.
You have to modify your imports , then the contract will get compile.
Refer..
https://github.com/OpenZeppelin/openzeppelin-contracts/issues/1557

When ever I try to compile the contract I keep getting a error on this line

In remix this line gives me a error "ParserError: Expected '(' but got identifier"
function setIsPublicMintEnabled(bool is PublicMintEnabled_) external onlyOwner {
isPublicMintEnabled=isPublicMintEnabled;
}
There is an syntax error around is keyword. Refactor your function in following way:
function setIsPublicMintEnabled(bool isPublicMintEnabled_) external onlyOwner {
isPublicMintEnabled = isPublicMintEnabled_;
}
is keyword is used when contract inheritance is being defined. Here is an detailed explanation how to use inheritance and the is keyword in practice.

I have tried to compile this code unfortunately i usually get error

This is the code: function () external payable {
The error when compiling:
ParserError: Expected a state variable declaration. If you intended this as a fallback function or a function to handle plain ether transactions, use the "fallback" keyword or the "receive" keyword instead. --> mytoken.sol:145:32: | 145 | function () external payable { | ^
This error occurs because you're using syntax from Solidity 0.5 or older in version 0.6 or newer.
In Solidity 0.6, the fallback function was changed, and the new syntax is
pragma solidity ^0.6;
contract MyContract {
fallback() external payable {
// TODO implement or leave empty
}
}
You can find more info in the docs section breaking changes.

Solidity: Nested mapping access cannot be at return

i'm writing simple smart contract for learning.
I wrote a contract as
contract A {
mapping(address => mapping(uint32 => uint32)) data;
..
function getData(address addr, index id) public view {
return data[addr][id];
}
}
And it returns compile error
TypeError: Different number of arguments in return statement than in returns declaration
In right that line.
Maybe there is miswriting in my code data[addr][index] , which one should be fixed,
or just a bug of Solidity?
Weirdly, i found answer right after posting..
Simply added returns keywords like
function getData(address addr, index id) public view returns(uint32) {
...
then works fine.
For others, i'll leave this question as is.

Chainlink VRF : Error encoding arguments: Error: invalid BigNumber string

I'm trying to get a random number with Chainlink VRF,
So Hi have follow this demo step by step : https://www.youtube.com/watch?v=JqZWariqh5s
here is what i've copied on Remix :
pragma solidity 0.6.6;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/master/evm-contracts/src/v0.6/VRFConsumerBase.sol";
contract RandomNumberConsumer is VRFConsumerBase {
bytes32 public keyHash;
uint256 public fee;
uint256 public randomResult;
constructor() VRFConsumerBase(
0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9, // VRF Coordinator
0xa36085F69e2889c224210F603D836748e7dC0088 // LINK Token
) public
{
keyHash = 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4;
fee = 0.1 * 10 ** 18; // 0.1 LINK
}
function getRandomNumber(uint256 userProvidedSeed) public returns (bytes32 requestId) {
return requestRandomness(keyHash, fee, userProvidedSeed);
}
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
randomResult = randomness.mod(50).add(1);
}
}
when i click on getRandomNumber, i always get this error :
Error encoding arguments: Error: invalid BigNumber string (argument="value", value="", code=INVALID_ARGUMENT, version=bignumber/5.0.8)
and with the fulfillRandomness, i get this error :
Error encoding arguments: Error: invalid arrayify value (argument="value", value="", code=INVALID_ARGUMENT, version=bytes/5.0.5)
Add some seed number into the function, and then click it.
Also, be sure to fund it with LINK.
Also, fulfillRandomness is only callable by the Chainlink VRF, so no worries on that part.
It looks like you are not passing the userProvidedSeed as an argument to getRandomNumber()
Try putting any number into the box beside the getRandomNumber method in Remix and then click on the method.
Also, fulfillRandomness is only callable by the Chainlink VRF, so do no worry about calling that function.