Avoid running out of gas, hash function

sanandreasanandrea Member Posts: 1
edited April 2015 in Smart Contracts and Dapps
Hello folks, I am trying to implement a simple smart contract that creates another smart contract with sole purpose to store data. This is my solidity code:

contract PublicData{
string32  key;
hash256 value;
	function PublicData(string32 inKey, hash256 inValue){
		key = inKey;
		value = inValue;

	function getData() returns (hash256 bbb){
		return value;

contract CDV {
	//owner of this contract
	address owner;
	struct UserField{
		string32 key;
		string32 value;

	//User data composed of primitive types
	struct UserData{
		mapping(uint => UserField) allData;

	mapping (uint => UserData) users;

	function CDV(){
		owner = msg.sender;

		var user = users[0];
		user.allData[0].key = "name";
		user.allData[0].value = "george";

		user.allData[1].key = "surname";
		user.allData[1].value = "orwell";
		var otherUser = users[1];
		otherUser.allData[0].key = "name";
		otherUser.allData[0].value = "mario";

		otherUser.allData[1].key = "surname";
		otherUser.allData[1].value = "rossi";

	function createPublicData(uint userID) returns (address aaa){
		var user = users[userID];
		var nameData = new PublicData("asdf", sha256("fdsa")); // <===== Problem of hash
		return address(nameData);
I inject this contract into the blockchain by utilizing AlethZero. The problem is that if i omit the hash operation (i.e. I save only a string) the PublicData smart contract is created correctly. If I leave the hash operation the execution runs out of gas and I don't know how to solve it. I call the createPublicData like this:

var CDV = web3.eth.contractFromAbi([{"constant":false,"inputs":[{"name":"userID","type":"uint256"}],"name":"createPublicData","outputs":[{"name":"aaa","type":"address"}],"type":"function"}]);
var cdvInstance = new CDV("0x0ec59de26755bf2d61e2ef17009a3917c2863f7d");
var newAddress = cdvInstance.call().createPublicData(1);

I have also tried by specifying the gas amount but with no luck:

var CDV = web3.eth.contractFromAbi([{"constant":false,"inputs":[{"name":"userID","type":"uint256"}],"name":"createPublicData","outputs":
var cdvInstance = new CDV("0x0ec59de26755bf2d61e2ef17009a3917c2863f7d");
cdvInstance.createPublicData(1,{value: 500, gas: 10000});
var newAddress = cdvInstance.call().createPublicData(1,{value: 600, gas: 10000});
Post edited by StephanTual on
Sign In or Register to comment.