Posts

Showing posts with the label #PhoneBook

"Phone Book Contract" Example Version 4

Image
In my previous post, any account could add and delete from the contract. so in this post i will be using "Modifiers" to check that only the creator of the contract can add and remove data but any one can view the phonebook Modifiers can be used to change the body of a function. Modifiers  let you wrap additional functionality to a method, so they're kind of like the decorator pattern in OOP. pragma solidity ^0.4.0; contract PhoneBookAresh{ //Declare a struct similar to C++ struct Person{ string fullName; string number; } //Events event Log(string name, string number); //An Array of structs similar to C++ (flexible storage) and index start at 0 Person[] MyPhoneBook; //whos phonebook it is. The Value is the Hex value of the account address creator; //this is a constructor, notice it has the same name as the Contract name function PhoneBookAresh() public { creator = msg.sender; ...

"Phone Book Contract" Example Version 3

In this version im making use of the following 1. Delete an item using an index from the array 2. Log the action using an "Event" Events are dispatched signals the smart contracts can fire. DApps, or anything connected to Ethereum JSON-RPC API, can listen to these events and act accordingly. Event can be indexed, so that the event history is searchable later. pragma solidity ^0.4.0; contract PhoneBookAresh{ //Declare a struct similar to C++ struct Person{ string fullName; string number; } //Events event Log(string name, string number); //An Array of structs similar to C++ (flexible storage) and index start at 0 Person[] MyPhoneBook; //whos phonebook it is. The Value is the Hex value of the account address creator; //this is a constructor, notice it has the same name as the Contract name function PhoneBookAresh() public { creator = msg.sender; } //Adds an item to the Pho...

"Phone Book Contract" Example Version 2

In this version of the phone book, i am making use of a function to verify if the name exists before adding it to the array what ive learned from this is: 1. Throw vs Revert 2. View vs Pure pragma solidity ^0.4.0; contract PhoneBookAresh{ //Declare a struct similar to C++ struct Person{ string fullName; string number; } //An Array of structs similar to C++ (flexible storage) and index start at 0 Person[] MyPhoneBook; //whos phonebook it is. The Value is the Hex value of the account address creator; //this is a constructor, notice it has the same name as the Contract name function PhoneBookAresh() public { creator = msg.sender; } //Adds an item to the Phonebook using PUSH function AddPhone(string _fullName, string _number) public { //if name doesnt exist. still uses GAS to go thru the loop if (CheckName(_fullName) == false) { MyPhoneBook.push(Person(_f...

"Phone Book Contract" Example

In this example ive learned the following concepts. The use of a loop The use of an if conditional statement The Creator of the contract is the same as the account holding Ether String comparison requires utility functions. You can also use the "import" keyword to import external solidity contracts. but i kept getting errors on Remix. Basic usage for "import" import "github.com/Arachnid/solidity-stringutils/strings.sol"; pragma solidity ^0.4.0; contract PhoneBookAresh{ //Declare a struct similar to C++ struct Person{ string fullName; string number; } //An Array of structs similar to C++ (flexible storage) and index start at 0 Person[] MyPhoneBook; //whos phonebook it is. The Value is the Hex value of the account address creator; //this is a constructor, notice it has the same name as the Contract name function PhoneBookAresh() public { creator = msg.sender; } ...