Posts

Showing posts with the label #ethereum

a few things about Web3.JS

web3.js will: We can create new accounts, we can send Ether, we can add signatures to transfers, get balances from accounts, get transactions, and transaction IDs. We can clone and we can interact with contracts, all kinds of stuff. where will it go? load it from metamask OR add it as a script to your HTML DAPP. <head> //load BootStrap CSS </head> <body> //content //load web3.js //load ABI.js //load jQuery //load Bootstrap js <script> //web3 provider </script> </body> The Web3.js Script part can use the following: // Checking if Web3 has been injected by the browser (Mist/MetaMask) if ( typeof web3 !== ' undefined ' ) { // Use Mist/MetaMask's provider web3js = new Web3 ( web3 . currentProvider ); web3js . version . getNetwork (( err , netId ) => { switch (netId) { case " 1 " : console . log ( ' This is mainnet ' ) break case " 2 " : ...

Ethereum Smart Contract Safe Math Checks

An overflow/underflow happens when an arithmetic operation reach the maximum or minimum size of the type.  An overflow condition gives incorrect results and, particularly if the possibility has not been anticipated, can compromise a program’s reliability and security. SafeMath  is a solidity math library especially designed to support  safe  math operations: safe means that it prevents overflow when working with  uint . You can find it in zeppelin-solidity  SafeMath . pragma solidity 0.4.24; // @title SafeMath // @dev Math operations with safety checks that throw on error library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { ...

Parity installation on Ubuntu Virtual Machine

Image
Im going to be installing Parity on a Virtual Machine. My current OS is a Windows 10 and use the following settings installing ubuntu should be by downloading the ISO and creating a new VM on oracle virtual machine and attaching the ISO file and running setup until you have installed Ubuntu. To Install Parity on your Ubuntu. Open the terminal window and type away: >sudo apt-get install rustc cargo >sudo apt-get install curl >bash <(curl https://get.parity.io -Lk) >sudo apt-get install snapd >sudo snap install parity-ui >sudo apt install npm >sudo snap install parity OPTIONAL:  (a just in case all the above fails and i dont know what those mean, you would want to do this) go to PARITY.IO download and install the parity debian build for ubuntu once installed. you can now see Parity and Parity UI in your applications Running Parity from the Applications Menu: click on parity first to open the terminal while keeping the terminal op...

Ethereum Blockchain with Azure

Image
Usually setting up a full environment for developing DApps with Ethereum blockchain is a complicating task. Microsoft Azure, offers a fantastic Virtual Machine with all of the tools installed, so im going to show this in this blog post. So this url shows the full image and the complete list of out of the box environment on azure you can select VM:Virtual Machine and Add+, then search for "Ethereum Development Kit" You always have the option of Creating the VM and Exporting it to a VHD to use on a local Virtual Machine. You can follow the instructions here to export to a VHD

Blockchain versions

Blockchain 1.0: Currency The implementation of distributed ledger technology (DLT) led to its first and obvious application: cryptocurrencies. This allows fincancial transactions based on blockchain technology or DLT  (for the sake of simplicity often seen as synonyms ) to be executed with  Bitcoin  being the most prominent example in this segment. It is being used as “cash for the Internet”, a digital payment system and can be seen as the enabler of an “Internet of Money”.   Blockchain 2.0: Smart Contracts The new key concept are  Smart Contracts,  small computer programs that “live” in the blockchain. They are autonomous computer programs that execute automatically and conditions defined beforehand such as the facilitation, verification or enforcement of the performance of a contract. One big advantage this technlogy offers, is the blockchain making it impossible to tamper or hack Smart Contracts. So Smart Contracts reduce the cost of verification, ...

Rust Basics for programming

Rust is not a particularly original language. Its design elements came from a wide range of sources.  ▸ Abstract Machine Model : C  ▸ Data types : C, SML, OCaml, Lisp, Limbo  ▸ Optional Bindings : Swift  ▸ Hygienic Macros : Scheme  ▸ Functional Programming : Haskell, OCaml, F#  ▸ Attributes : ECMA-335  ▸ Memory Model and Memory Management : C++, ML Kit, Cyclone  ▸ Type Classes : Haskell  ▸ Crate : Assembly in the ECMA-335 CLI model  ▸ Channels and Concurrency : Newsqueak, Alef, Limbo  ▸ Message passing and Thread failure : Erlang Rust files should have .rs file extension and if you’re using more than one word for the file name, use lower case and separate words with an underscore (snake_case) To Compile rustc file.rs Cargo is Rust’s build-in Package Manager. But mainly it uses for,  ▸ Create new project : cargo new  ▸ Update dependencies : cargo update  ▸ Build project : cargo build  ▸ ...

Crypto-Currency "Coin Contract" Example

Image
So here is my starting point pragma solidity ^0.4.18; //Used like an Interface in C# or Java contract Token { function totalSupply() public constant returns (uint256 supply) {} function balanceOf(address _owner) public constant returns (uint256 balance) {} function transfer(address _to, uint256 _value) public returns (bool success) {} function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {} function approve(address _spender, uint256 _value) public returns (bool success) {} function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {} //needed to Log the Events event Transfer(address indexed _from, address indexed _to, uint256 _value); event Approval(address indexed _owner, address indexed _spender, uint256 _value); } contract StandardToken is Token { mapping (address => uint256) balances; mapping (address => mapping (address => uint25...

Blockchain IoT Example "Iris Contract"

In this post i will be creating a contract that works with a device (a device that can acquire your IRIS (EYE) Data and use it for Unlocking or Security. How is it an IoT? Source The  Internet of things  ( IoT ) is the network of physical devices, vehicles, home appliances, and other items  embedded  with  electronics ,  software ,  sensors ,  actuators , and  network connectivity  which enable these objects to connect and exchange  data . There are many Cheap Hardware devices currently in the market that can provide and Iris Code. One of these devices is the Samsung Note 7 that has a built in Iris Scanner for Unlocking Phone as a Secondary Authentication   Source So assuming i have the hardware that can get My Iris Scanned. What will be the output of this Hardware? How do iris Scan work?  identifies around 240 unique features (about five times more "points of comparison" as fingerprint systems use). The...

Blockchain Business Example "Smart Property Contract"

This contract is for tangible and intangible property such as Cars, Houses or Patents. Can be used to record and verify property rights. First,  payable  is a modifier that can be added to a function. It's impossible to have  payable()  as a function name as it is a reserved keyword. You may use  payable  only in addition to existing functions  Second,  Payable  allows a function to receive ether while being called as stated in  docs .It's manadatory from solidity 0.4.x. If you try to send ether using  call pragma solidity ^0.4.18; contract LandAresh { address public owner; uint public defaultCost; uint public mainLandCost; mapping(uint => mapping(uint => address))public properties; mapping(uint => mapping(uint => address))public landContent; mapping(uint => mapping(uint => bool))public status; mapping(uint => mapping(uint => uint))public prices; funct...

Dear Diary Example "Blog Contract"

In this post, i will be creating a Blogging Contract meant for Diary Entries and posts of articles or News. Notice the use of "block.number" in this post as a way to see new blocks as they come in or get changed contract BlogAresh { address public owner; blog[] blogLogs; struct blog { string title; string headline; string content; string url; address owner; uint blocknumber; } uint counter; function BlogAresh() public { owner = msg.sender; counter = 1; blogLogs.push(blog("BlogAresh:", "My New Blog", "1.0","ethereumacademy.blogspot.com", owner, block.number)); } //anyone can add a post to the blog (multiple writers) function addPost(string title, string headline, string content, string link) public { blogLogs.push(blog(title, headline, content, link,msg.sender, block.number)); counter += 1; } ...