I am trying to update the value of one of the props in a struct in a solidity contract.
updating a variable works fine if it is not in a struct. but when i try to update a value in a struct like in the contract below, gas is used to update the contracts as i would expect, but when i read the updated value, it has not been changed.
Can anyone see how my contracts definition is incorrect?
My contract is defined as:
Users.sol
pragma solidity ^0.4.17;
contract Users {
struct User {
string firstName;
string lastName;
}
mapping(address => User) public users;
function getFirstName() public view returns (string) {
User memory user = users[msg.sender];
return user.firstName;
}
function setFirstName(newName) public {
User memory user = users[msg.sender];
user.firstName = newName;
}
}
i'm new to working with solidity so any help is appreciated.
function setName(string newName) public { temps[msg.sender].name = newName; }, but this does not work either. – X0r0N Mar 11 '18 at 22:52setNamevs.setFirstNameandtempsvs.users). Can you describe how you're calling the function? – user19510 Mar 11 '18 at 22:54call, which does not modify state. – user19510 Mar 11 '18 at 22:55function setFirstName(string newName) public { users[msg.sender]. firstName = newName; }. i am using web3 on react-native, which works fine when interacting with contracts. i only have this issue with structs. i am calling the function from custom redux middleware (which i have tested to work)export const setFirstName = newName => ({ type: 'set first name', promise: ({ contracts, coinbase }) => contracts.Users.setFirstName(newName, { from: coinbase }) });– X0r0N Mar 11 '18 at 23:04