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,370 points
4,710 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
• 69,220 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 May 1, 2019 by Raj
0 votes
Could be a version problem. This worked for me on version 0.4.10. Try it.
answered May 1, 2019 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 8, 2018 in Blockchain by Shashank
• 10,400 points
922 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 2, 2018 in Blockchain by Shashank
• 10,400 points
745 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,740 points
823 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
1,938 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,740 points
45,280 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,465 views
0 votes
1 answer

truffle compile shows error: TypeError: Invalid type for argument in function call.

You are getting this error because you ...READ MORE

answered Dec 5, 2018 in Blockchain by Omkar
• 69,220 points
2,240 views
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
• 69,220 points
798 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP