Solidity: TypeError: Data location must be "memory" for parameter in function, but none was given.

0 votes

My function:

function add_voter(address add_of_voter, string name_of_voter)public {

require (msg.sender == admin, "Action prohibited! Adding voter can only be done by Admin");

                voters[voter].voter_add = add_of_voter;

                voters[voter].voter_name = name_of_voter;

}

When I run the code, I get this error:

TypeError: Data location must be "memory" for parameter in function, but none was given. 

How to solve it?

Dec 12, 2018 in Blockchain by slayer
• 29,060 points
953 views

3 answers to this question.

0 votes

When you are using a string argument, you have to mention where you want store the data. So, try this:

function add_voter(address add_of_voter, string memory name_of_voter)public {

require (msg.sender == admin, "Action prohibited! Adding voter can only be done by Admin");         

                voters[voter].voter_add = add_of_voter;

                voters[voter].voter_name = name_of_voter;

}
answered Dec 12, 2018 by Omkar
• 67,540 points
0 votes

You can to explicitly mention that the string is a memory. Change the first line of your code to this:

function add_voter(address add_of_voter, string memory name_of_voter)public {
answered Apr 30 by Raj
0 votes
Could be a version problem. This worked for me on version 0.4.10. Try it.
answered Apr 30 by Yogi
Facing same problem with this version also.
Are you running it on Remix IDE or on your system?
Tried both. Doesn't work. I tried the solution in another answer and one of it worked.

Related Questions In Blockchain

+1 vote
1 answer

Can a data be altered in a blockchain without changing its hash?

Yes, it should work. The authentication practice ...READ MORE

answered Apr 7, 2018 in Blockchain by Shashank
• 10,350 points
43 views
0 votes
1 answer

What could be the best term to use for the collection of contracts in a .sol file?

module - don't think so. Because module ...READ MORE

answered Jun 1, 2018 in Blockchain by Shashank
• 10,350 points
34 views
0 votes
1 answer
0 votes
1 answer

What encoding or data type can be used to get alphanumeric string in elixir?

Integers in Elixir are arbitrary precision integers, ...READ MORE

answered Aug 31, 2018 in Blockchain by digger
• 26,550 points
47 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
141 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,550 points
3,133 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Sending hash in function parameter

I am developing a smart contract using ...READ MORE

answered Oct 8, 2018 in Blockchain by Omkar
• 67,540 points
67 views