pragma solidity ^0.6.0;
contract MyContract {
// Mappings
mapping(uint => string) public names;
constuctor() public {
names[1] = "Adam";
names[2] = "Bruce";
names[3] = "Carl";
}
}
I tried compiling this code on remix.ethereum.org and I got the following error:
Solidity ParserError: Expected identifier but got '(' constuctor() public { ^
How can I go about solving this issue? Could anyone please help?
You have a typo in your constructor declaration :
constructor() public {
instead of
constuctor() public {
"r" is missing
Related
I've seen this code working in many factory contracts:
constructor() public {
uint chainId;
assembly {
chainId := chainid
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes(name)),
keccak256(bytes('1')),
chainId,
address(this)
)
);
}
However, this works when I use
pragma solidity =0.5.16;
But if I use pragma solidity =0.6.12;, I get an error:
ParseError: Expected '(' but got '}' } ^
I tried to do the following:
constructor() public {
uint chainId;
assembly {
chainId := chainid()
}...
But then I get multiple errors on variables and functions saying:
TypeError: overriding public state variable is missing string public constant name = ...
How do I write the assembly line in solidity version 0.6.12?
Thank you,
Using version 0.5.16 it's not an option because many imports use 0.6.12 and they won't work...
//SPDX-License-Identifier: MIT
pragma solidity =0.6.12;
contract Test {
string public constant name = "Your Contract name";
constructor() public {
uint chainId;
assembly {
chainId := chainid()
}
bytes32 DOMAIN_SEPARATOR;
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes(name)),
keccak256(bytes('1')),
chainId,
address(this)
)
);}}
Try this. If you upgrade your code to version 0.8.0 and above there is a variable available in global namespace called
block.chainid
I am trying to create my first Smart Contract but how is it possible that the error says invalid argument?, please consider that with the first method (CreateITem) everything works fine... that's for saying that it's not a problem of invalid ABI or invalid contract address ?
The error is : throw new Error('incorrect number of arguments');
pragma solidity ^0.5.0;
contract ItemsList {
uint public itemCount = 0;
mapping(uint => Item) public items;
struct Item {
string encryptedProofHash;
}
function createItem(string memory _encryptedProofHash) public {
items[itemCount] = Item(_encryptedProofHash);
itemCount++;
}
function getItemCount() public view returns (uint){
return itemCount;
}
}
...and this is the code for reading using ethers.js
var wallet = new ethers.Wallet(privateKey,provider);
var contract = new ethers.Contract(address,abi,wallet);
var sendPromise = contract.getItemCount(); ------------------->> ERRROR
sendPromise.then(function(transaction){
console.log(transaction);
}).catch((error) => {
console.error(error)
});
I found it, just remove the build folder and generate again the contract
I want to get the value that is inside of struct in Solidity,
but I have no idea how to get it.
pragma solidity >=0.4.21 <0.6.0;
contract PlaceList {
struct hoge {
uint id;
address user;
}
hoge[] public hoges;
constructor() public {
admin = msg.sender;
}
function set(uint id) public {
hoges.push(hoge(id, msg.sender));
}
function getId() public view returns(uint) {
return (hoges[0].id);
}
}
When I call getId, console command say this,
ƒ () {
if (abiItemModel.isOfType('constructor')) {
return target.executeMethod(abiItemModel, arguments, 'contract-deployment');
}
return targe…
Could you give me any advise how to get id by using solidity function, please?
hoges[0][0] will work as it points to the first element, 'id' .
I'am trying to deploy a smart contract :
`
pragma solidity >=0.4.21;
contract SimpleStorage {
uint public storedData;
constructor(uint initVal) public {
storedData = initVal;
}
function set(uint x) public {
storedData = x;
}
function get() view public returns (uint retVal) {
return storedData;
}
}`
I have created 2_deploy.js
var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
// Pass 42 to the contract as the first constructor parameter
deployer.deploy(SimpleStorage, 42, {privateFor:
["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};
but when I execute truffle.migration I obtain this error:
'Error encountered, bailing. Network state unknown. Review
successful transactions manually.
Error: Invalid number of parameters for "undefined". Got 2
expected 1!
at Object.InvalidNumberOfParams
(/usr/lib/node_modules/truffle/build/webpack:/~/web3-eth-
contract/~/web3-core-helpers/src/errors.js:32:1)
at Object._createTxObject
(/usr/lib/node_modules/truffle/build/webpack:/~/web3-eth-
contract/src/index.js:699:1)
at Contract.deploy
(/usr/lib/node_modules/truffle/build/webpack:/~/web3-eth-
contract/src/index.js:504:1)
at Function.deploy
(/usr/lib/node_modules/truffle/build/webpack:/packages/truffle-
contract/lib/execute.js:214:1)
at constructor.detectNetwork.then.network
(/usr/lib/node_modules/truffle/build/webpack:/packages/truffle-
contract/lib/contract/constructorMethods.js:56:1)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Truffle v5.0.13 (core: 5.0.13)
Node v8.9.4''
do anyone knows how to deal with the problem?
Truffle has only recently added support for quorum private transactions. So you need Truffle version 5.0.14.
I hope that helps.
I tried to write a smart contract which is able to complaining. Here is the code
pragma solidity ^0.4.2;
contract Complain {
//Model Complain
struct compalins {
uint id;
string category;
string desc;
string complainer;
}
mapping( uint => complains) public newComplain;
uint public complainCount;
function Complain () public {
addComplain("c1","bhbh","bybhb");
addComplain("c2","bhbh","bybhb");
}
function addComplain (string _category,string desc,string complainer){
complainCount ++;
// newComplain[ComplainCount] = complains(complainCount,_category,desc,complainer);
}
}
in this mapping function gives an error and say structure of the complains haven't Unique value. But id is Unique.
Please help me to solve this issue
You misspelled "complains" when you declared your struct. (You spelled it "compalins" there.) So the error on the mapping line is that there's no such identifier "complains". If you fix the typo, the code will compile.