I made a little smart contracts with solidity browser,
This is my code:
pragma solidity ^0.4.0;
contract Test {
struct User {
string name;
string surname;
uint active;
}
mapping(bytes32 => User) public userRegister;
function add_user(string _name, string _surname) {
bytes32 _hc=sha3(_name, _surname);
User p = userRegister[_hc];
p.name=_name;
p.surname=_surname;
p.active=1;
}
function remove(string _name, string _surname) {
bytes32 _hc=sha3(_name, _surname);
userRegister[_hc].active=0;
}
function active(string _name, string _surname) {
bytes32 _hc=sha3(_name, _surname);
userRegister[_hc].active=1;
}
}
When I use "JavaScript VM" everything's fine, but when I compile the contract with Injected Web3 there is a problem.
Adding a user (with add_user) it's all okay, but when i try to remove a user, i get an error:
callback contain no result Error: Out of gas
After some test i supposed that error is given when I try to set a uint value to zero.
Then I try to change the 0 in
userRegister[_hc].active=0;
with 9(or other int number)
userRegister[_hc].active=9;
And all works fine.
So, someone can tell me what's wrong with set a uint value to 0? And how i can re-set a uint variable to zero?
Thanks
Best Answer
Summary
This somehow seems to be a problem with Browser Solidity interacting with
geth
. When I deploy the contract and execute the transactions directly ingeth
, the contract works as expected.@PietroR91
, please submit your code as an issue in the Browser Solidity github. If you are unable to do so, I can do it later.Details
Environment
The error in Browser Solidity has been verified with the pragma and compiler being
^0.4.0
,^0.4.4
and^0.4.7
.The
geth
environment I am using is version 1.5.5-stable on OS/X.Modified Source Code
Here is your source code, modified by the addition of
getUser(...)
to check the values of the data in the mapping, and some minor formatting changes:Browser Solidity - Deploy And Execute
add_user(...)
Browser Solidity - Attempt To Execute
remove(...)
When attempting to execute
remove(...)
in Browser Solidity, the messagecallback contain no result Error: Intrinsic gas too low
is displayed.Browser Solidity - Web3 Deploy
Following is the Web3 Deploy code from Browser Solidity:
Deploying The Contract In
geth
I paste the Web3 Deploy code from the previous section into my Dev
geth
console:Executing The Functions In
geth
I then executed the following functions in
geth
:Checking the function got executed correctly:
Let's now execute the
remove(...)
function with the problem:Checking the function got executed correctly:
An Interesting Observations
If I modify
remove(...)
to add the following:I am able to execute the function in Browser Solidity, but the returned from
getUser(...)
shows that the value of active is not modified from 1 to 0.Executing The Modified
remove(...)
function in Browser SolidityThe following screen shows the
remove(...)
function being successfully executed in Browser Solidity:Following is the transaction receipt in
geth
:The following screen shows the second invocation of
getUser(...)
where the results are unchanged.active
is still1
instead of the expected0
: