0

I am trying to do truffle migrate but i got this error

$ truffle migrate

Compiling .\contracts\Election.sol...
Compiling .\contracts\Migrations.sol...

Compilation warnings encountered:

/C/Users/asus/election/contracts/Election.sol:24:5: Warning: This declaration shadows an existing declaration.
function Election () public {
^ (Relevant source part starts here and spans across multiple lines).

/C/Users/asus/election/contracts/Election.sol:3:1: The shadowed declaration is here:
contract Election {
^ (Relevant source part starts here and spans across multiple lines).

/C/Users/asus/election/contracts/Election.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity 0.4.24;
^---------------------^

/C/Users/asus/election/contracts/Election.sol:24:5: SyntaxError: 
Functions are not allowed to have the same name as the contract. If you intend this to be a constructor, use "constructor(...) { ... }" to define it.
function Election () public {
^ (Relevant source part starts here and spans across multiple lines).

/C/Users/asus/election/contracts/Migrations.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.24;
^----------------------^

,/C/Users/asus/election/contracts/Election.sol:24:5: Warning: This declaration shadows an existing declaration.
function Election () public {
^ (Relevant source part starts here and spans across multiple lines).

/C/Users/asus/election/contracts/Election.sol:3:1: The shadowed declaration is here:
contract Election {
^ (Relevant source part starts here and spans across multiple lines).

/C/Users/asus/election/contracts/Election.sol:29:28: TypeError: Data location must be "storage" or "memory" for parameter in function, but none was given.
function addCandidate (string _name) private {
                       ^----------^
Compilation failed. See above.
Truffle v5.0.1 (core: 5.0.1)
Node v11.6.0

What am I supposed to do?

  • You should share your source code in order to get the best help. A lot of the errors seem pretty straightforward, and I think all of them are because you updated to Truffle v5 (solidity 0.5.0). This comes with some breaking changes, so you should edit your contract accordingly (See Solidity 0.5.0 breaking changes). – Rosco Kalis Jan 5 at 16:12
1

From what I am understanding, try to use a more recent solidity compiler writing as statement pragma solidity ^0.5.0; since you are using truffle v 0.5.

With Solidity 0.5 you must declare a constructor with constructor keyword (as one of your errors states).

For your last listed error now you need to specify whether your arrays parameters are memory or storage. Try to change the signature of addCandidate (string _name) to addCandidate (string memory _name).

For more information like these check the changelog for solidity v 0.5 here: https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html

0
TypeError: Data location must be "storage" or "memory" for parameter in the function, but none was given.
function addCandidate(string _name) private{

For this type of error try to change the array parameters whether they belong to Storage or memory. add memory to your function local variable.

function addCandidate(string memory _name) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.