Posts

Showing posts with the label #ToDo

"To Do List Contract" With Remix

Image
For this Post, i am using Remix to see the result of the contract. pragma solidity ^0.4.0; contract ToDoAreshFlexible{ //Declare a struct similar to C++ holding details of a single ToDo Item struct Item{ string task; uint priority; } //An Array of structs similar to C++ (flexible storage) and index start at 0 Item[] ToDoList; //this is a constructor, notice it has the same name as the Contract name function ToDoAreshFlexible() public { } //Adds an item to the list using PUSH function AddToDo(string _task, uint _priority) public { ToDoList.push(Item(_task,_priority)); } //returns a single item given an index since it requires more gas to iterate thru //returning multiple Items, both task and priority with a single call function getToDoList(uint _index) public returns(string, uint ){ return (ToDoList[_index].task, ToDoList[_index].priority); } function GetTa...

Returning Multiple Values for the "To Do List Contract" Example

In this post i learned how to add items to a fixed array . on this post i extended this contract by making use of a flexible array size . in both posts, i was only returning the task and no the priority. In this post i will be returning multiple values pragma solidity ^0.4.0; contract ToDoAreshFlexible{ //Declare a struct similar to C++ holding details of a single ToDo Item struct Item{ string task; uint priority; } //An Array of structs similar to C++ (flexible storage) and index start at 0 Item[] ToDoList; //this is a constructor, notice it has the same name as the Contract name function ToDoAreshFlexible() public { } //Adds an item to the list using PUSH function AddToDo(string _task, uint _priority) public { ToDoList.push(Item(_task,_priority)); } //returns a single item given an index since it requires more gas to iterate thru //returning multiple Items, both task and priorit...

Non fixed Number of Items for a "To Do List Contract" Example

In this example i will be using an array in storage compared to the Previous Post of a Fixed Number of items in the Array pragma solidity ^0.4.0; contract ToDoAreshFlexible{ //Declare a struct similar to C++ holding details of a single ToDo Item struct Item{ string task; uint priority; } //An Array of structs similar to C++ (flexible storage) and index start at 0 Item[] ToDoList; //this is a constructor, notice it has the same name as the Contract name function ToDoAreshFlexible() public { } //Adds an item to the list using PUSH function AddToDo(string _task, uint _priority) public { ToDoList.push(Item(_task,_priority)); } //returns a single item given an index since it requires more gas to iterate thru function getToDoList(uint _index) public returns(string ){ return ToDoList[_index].task; } }

Fixed Number of Items for a "To Do List Contract" Example

So in this post, i have a "To Do List" with constant number of items pragma solidity ^0.4.0; contract ToDoAreshConstant{ //Declare a struct similar to C++ holding details of a single ToDo Item struct Item{ string task; uint priority; } uint CurrentItem; //An Array of structs similar to C++ with 10 items (reserves storage) and index start at 0 Item[10] ToDoList; //this is a constructor, notice it has the same name as the Contract name function ToDoAreshConstant() public { CurrentItem = 0; //Assign to zero when contract is created. } //Adds an item to the list and increments the position of the index function AddToDo(string _task, uint _priority) public { ToDoList[CurrentItem] = Item(_task,_priority); CurrentItem++; } //returns a single item given an index since it requires more gas to iterate thru function getToDoList(uint _index) public returns(string ){ ...