Solidity Contracts
Jump to navigation
Jump to search
Solidity Contract
pragma solidity ^0.4.0; contract HelloWorldContract{ string word = "Hello"; address public issuer; // constructor function HelloWorldContract(){ issuer = msg.sender; } modifier ifIssuer(){ if(issuer != msg.sender){ throw; } else{ _; // this means continue } } // creating a getter // the keyword constant is used to make it a getter without it the contract would // use gas and would be a setter function getWord() constant returns(string){ return word; } // setter function setWord(string newWord) returns(string){ word = newWord; return word; } }
Bank account
pragma solidity ^0.4.0; contract BankAccount{ address client; bool _switch = false; // event will fire when called only workd in setters event UpdateStatus(string _msg, uint _amount); event test(string _msg2); // constructor function BankAccount(){ client = msg.sender; } // this will allow only the owner of the contrat to use /* so you create the modifier then add it to the functions that you want it to affect */ modifier ifClient(){ if(msg.sender != client){ throw; } _; } function depositFunds() payable{ UpdateStatus("User has deposited", msg.value); test("funds deposited"); } function witdrawFunds(uint amount) ifClient{ // this returns a boolean if(client.send(amount)){ UpdateStatus("User has deposited ", 0); _switch = true; }else{ _switch = false; } } function getFunds() ifClient constant returns(uint) { return this.balance; } }// end contract