MENU

TutorialToken smart contract with Truffle

June 10, 2019
0
671
0
If you are trying to go through the token tutorial by Truffle there are a few things to note. If you follow the instructions fully, it will not work. Firstly the pragma version needs to be updated from 0.4.24 to 0.5.0. This is because if you install Truffle, it will install the latest version of solc, the solidity compiler which will be 0.5.8 at this time of writing. Next, if you run “npm run dev”, you might encounter and error like ERR! tutorialtoken@1.0.0 dev: `lite-server`. If you do, you’ll want to fix it by doing this. Then you’ll want to make sure the Metamask is either not yet installed or that it is disabled. Otherwise the tokens will appear in Metamask instead of on the webpage. Finally, you need to change the port in app.js from 9545 to 7545 which is the Ganache port. The tutorial is great but is several years old so needs these modifications.
Read More ›

tutorialtoken@1.0.0 dev: `lite-server`

June 7, 2019
0
674
0
If you are going through the Truffle TokenTutorial smart contract and you can’t run “npm run dev” because you get the following error below, it can be very frustrating. You follow all the instructions to the letter but get this strange error such as: – Cannot find module ‘../lib/lite-server’– ERR! code ELIFECYCLE– ERR! tutorialtoken@1.0.0 dev: `lite-server` Seans-MacBook-Pro:tokentutorial sean$ npm run dev > tutorialtoken@1.0.0 dev /Users/sean/Dropbox/CodeDropBox/truffle/tokentutorial > lite-server internal/modules/cjs/loader.js:626 throw err; ^ Error: Cannot find module '../lib/lite-server' Require stack: - /Users/sean/Dropbox/CodeDropBox/truffle/tokentutorial/node_modules/.bin/lite-server at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15) at Function.Module._load (internal/modules/cjs/loader.js:527:27) at Module.require (internal/modules/cjs/loader.js:681:19) at require (internal/modules/cjs/helpers.js:16:16) at Object. (/Users/sean/Dropbox/CodeDropBox/truffle/tokentutorial/node_modules/.bin/lite-server:7:1) at Module._compile (internal/modules/cjs/loader.js:774:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10) at Module.load (internal/modules/cjs/loader.js:641:32) at Function.Module._load (internal/modules/cjs/loader.js:556:12) at Function.Module.runMain (internal/modules/cjs/loader.js:837:10) { code: 'MODULE_NOT_FOUND', requireStack: [ '/Users/sean/Dropbox/CodeDropBox/truffle/tokentutorial/node_modules/.bin/lite-server' ] } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! tutorialtoken@1.0.0 dev: `lite-server` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the tutorialtoken@1.0.0 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /Users/sean/.npm/_logs/2019-06-09T09_13_38_647Z-debug.log https://github.com/node-inspector/node-inspector/issues/1044 As with most computer problems, when all else fails, restart, here a clean install of npm resolved this issue for me. […]
Read More ›

Sublime and Solidity Syntax in 10 seconds

June 4, 2019
0
785
0
If you are using Sublime, which is a very fast and lightweight text editor, to create smart contracts in Solidity, to get syntax highlighting, do the following: ⌘+⇧+P (command+shift+P) to bring up Sublime’s command palette, which is an interactive list whose purpose is to execute commands. Start typing “install” and select “Install Package”. Then wait a few seconds before another text box appears before typing “Ethereum” and select the first option. Before: After: To check that it has been installed, bring up the command palette and type “remove” and select remove package and Ethereum should appear indicating that it has been successfully installed.
Read More ›

ConsenSys Academy at Ethereal New York

May 23, 2019
0
1099
0
I was fortunate enough to have the opportunity to speak at a blockchain conference called Ethereal Summit in New York recently. It was a two day conference that focused on developments in the blockchain space and was also part of the run up to blockchain week where a three day conference run by Coindesk called “Consensus” and a one day Token Summit conference was held. I shared some of the work we’ve been doing at ConsenSys Academy with a talk called “Reinventing the way we learn blockchains”. Here is the presentation for those interested. I also had the chance to visit ConsenSys HQ in Brooklyn which is fast becoming a must see tourist spot for all those in the blockchain space. 10 points for guessing which graffiti covered door is the entrance into the office! If you can’t figure it out, use the next picture as a clue. I’m sitting outside on the front steps. In New York, I also got to meet the rest of the Academy team for the first time in 3D. ie “IRL” aka In Real Life. I must say that I’m very privileged to work with a bunch of very talented and dedicated people from […]
Read More ›

Sydney Edcon 2019 Wrap

April 19, 2019
0
1700
1
The week of April 8th was Blockchain week in Sydney with many blockchain events culminating in Edcon where Vitalik and his research crew shared their vision of Ethereum 2.0 The Hackathon The week started out with a hackathon at the University of New South Wales (UNSW) where there were lots of teams hacking it out for various cash prizes. What is funning is the story of CryptoChicks. One of the most inspiring team was CryptoBeast mentored by a good friend Nick Addison who entered his son and 3 of his mates. They were all 11 years old and ended up coming third! The most important question though is what do you do with a 6 ft cheque of $2000? Well, it may not provide much warmth as a blanket but it sure does look good! On Wednesday evening, ConsenSys put on an event at Tyro Fintech Hub with a number of guest speakers. Edcon Thursday was when Edcon started and boy did it start with a bang. It actually started with a hilarious rap! The schedule was very full on where the heavy hitters dominated the first day. You had to bring your thinking caps though because some of the […]
Read More ›

Training trainers at SK in Korea

February 25, 2019
0
3614
0
I had opportunity to provide blockchain train the trainer to SK Global in Korea which is another level up from regular training. SK Global or SK Holding is one of the largest conglomerates in South Korea comprising of around 95 subsidiaries. SK Global has more than 70,000 employees and 113 offices worldwide. My esteemed colleagues Coogan and Luiz, travelled to Korea in December and provided blockchain training to SK. They did an amazing job which pathed the way for part 2 of this training. I arrived on Sunday morning after taking the red eye from Sydney to Tokyo and then connecting to Seoul. I had to be rerouted due to weather conditions at Sydney airport but that is another story in itself. Seoul was cold! It may not feel like it if you’re only outside for a few minutes but very quickly you can feel your ears tingle. On day 1 we went through the plan for the week and reviewed the 1 day non technical edition as well as the first day of smart contracts for developers. The trainees had already gone through the material so this served as a refresher and provided more opportunities for in-depth discussions on […]
Read More ›

Remix MSTORE bug

February 12, 2019
0
3456
1
I was looking into strings v bytes into a bit more detail and started comparing the gas consumption between them. The following code was used: pragma solidity ^0.5.0; contract StringVersusByte { string constant _string = "hello"; bytes32 constant _bytes = "hello"; function getAsString() pure public returns(string memory) { return _string; } function getAsBytes() pure public returns(bytes32) { return _bytes; } } After deploying, I executed the the getAsBytes() first and saw that the execution cost was 196 gas. I then looked to confirm this by stepping through the debugger and summing up the cost of all the op codes. What I discovered was that it summed up to 172 and not 196 gas. I was out by 24 gas. I then looked at the debugger and looked at the remaining gas field. It should reduce by the amount of gas but in step 3 it doesn’t. It reduces by 12 instead of 3 as can be seen in the video. The culprit opcode is MSTORE and there are 2 MSTORE which makes up the missing 24 gas. In the video, the remaining gas decreases by the expected amount until it reaches step 3. This issue is highlighted as a bug […]
Read More ›

EVM Illustrated

January 24, 2019
0
3868
0
Here is a neat 116 slide deck that goes through what Ethereum is, the EVM and how it all works by Takenobu Tani. It is a pretty useful explanation but does go into a lot of detail such as endian and byte addressing which is quite low level. Here is a link to the pdf and here is the GitHub.
Read More ›

Where is DeployedAddresses.sol?

January 11, 2019
0
4410
1
If you are creating test scripts in solidity, you may have come across these import statement: import "truffle/Assert.sol"; import "truffle/DeployedAddresses.sol"; import "../contracts/HelloWorld.sol"; The last one is easy to understand because it is your smart contract in the “contracts” folder but what about Assert.sol and DeployedAddresses.sol? First of all, “truffle” refers to the global truffle repo which can be found at usr/local/lib/node_modules/truffle. Assert.sol lives at: usr/local/lib/node_modules/truffle/build/Assert.sol The trick is, what about DeployedAddresses.sol? You won’t find this file in the global truffle repo and a terminal search will be chocolateless fruitless. The reason is because this file is dynamically created at test time. (Kindalike the geth.ipc file that gets generated when geth is running but disappears when geth is stopped). “truffle” is a meta package, ie “these packages do not contain actual software, they simply depend on other packages to be installed“. In fact, if you look at the deploy.js source code, you’ll see the DeployedAddresses file get created via the code. Source: https://github.com/trufflesuite/truffle/issues/471 https://github.com/trufflesuite/truffle-core/blob/b3ad375993ec42bc622c7674258edc7614944482/lib/testing/deployed.js https://askubuntu.com/questions/66257/what-is-the-difference-between-a-meta-package-and-a-package
Read More ›

Truffle Box at URL … doesn’t exist

January 2, 2019
0
4760
0
If you have just created a new folder and ran truffle init and got an error similar to below truffle init Downloading… Error: Truffle Box at URL https://github.com/truffle-box/bare-box.git doesn’t exist. If you believe this is an error, please contact Truffle support. at Request._callback (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-box/lib/utils/unbox.js:50:1) at Request.self.callback (/usr/local/lib/node_modules/truffle/build/webpack:/~/request/request.js:185:1) at Request.emit (events.js:189:13) at Request. (/usr/local/lib/node_modules/truffle/build/webpack:/~/request/request.js:1157:1) at Request.emit (events.js:189:13) at IncomingMessage. (/usr/local/lib/node_modules/truffle/build/webpack:/~/request/request.js:1079:1) at Object.onceWrapper (events.js:277:13) at IncomingMessage.emit (events.js:194:15) at endReadableNT (_stream_readable.js:1107:12) at process.internalTickCallback (internal/process/next_tick.js:72:19)   then try to do “npm uninstall -g truffle” and then “npm install -g truffle”. When I did this I got: Preparing to download ✔ Downloading ✔ Cleaning up temporary files ✔ Setting up box Unbox successful. Sweet! Frustrating that it happened in the first place!
Read More ›

Understanding basic functions in solidity

December 22, 2018
0
5140
0
Smart contracts are comprised mainly of functions so it is important to understand how to construct one and all the various options available. From the solidity documentation, the syntax of a function is as follows: function FunctionName([parameters]) {public|private|internal|external} [pure|constant|view|payable] [modifiers] [returns (<return types>)] What this means is that when creating a function, here are the required steps. Use the function keyword Provide a function name Provide parameters if required Set the function’s visibility. There’s 4 options to choose from. public, private, internal, or external: Set the behaviour of the function. Choose from view, pure, or payable. Add any applicable modifiers Add any applicable return types/parameters Here is a brief explanation of the different visibilities. Public: All (contracts can a call the function) Private: Only this contract Internal – only this contract and contracts deriving from it External – Cannot be accessed internally, only externally. Private is a subset of internal and external is a subset of public. For a more detailed and intriguing analysis of the difference between public and external check this. (TLDR: public uses more gas because it uses memory instead of calldata). Check the docs more details The behaviours are defined as: View: Can read the state but will not modify storage state […]
Read More ›

Checklist for developing smart contracts

December 15, 2018
0
5122
0
To start developing smart contracts in solidity, here is a check list of applications that will make your life easy. Note: Instructions here are geared towards Mac operating system. Remix Remix is an online Integrated Development Environment (IDE) where solidity smart contracts can be written. It can then be compiled and tested locally or combined with Metamask and deployed on testnet for instance. Editors – Atom or Sublime Atom or Sublime are popular editors. Atom is open source (ie free) while Sublime costs $80USD. While solidity smart contracts are written in remix, editors are useful to handle json, javascript and regular text files. Metamask Metamask is a browser extension that allows smart contracts to connect to various blockchains. It can be thought of as a bridge connecting the two together. Geth Geth or Go Ethereum is an Ethereum client which when run, acts as a node to connect to the Ethereum blockchain. It can be configured to point to mainnet, testnet or even set up in private mode. The following command will tell you if you have geth installed or not. > geth version Geth Version: 1.8.14-stable Architecture: amd64 Protocol Versions: [63 62] Network Id: 1 Go Version: go1.10.3 Operating […]
Read More ›

How long does it take to do geth sync?

October 6, 2018
1
7648
0
Here are some latest stats on how long it takes to synchronise with the Ethereum blockchain. Geth can run in 3 modes. Fast, full or light. In light mode, geth gets only the current state. To verify elements, it needs to ask to full (archive) nodes for the corresponding tree leaves. Light > geth --syncmode=light will take about 15-20 minutes and take about 500Mb of disk space. The starting block was about 300,000 blocks behind the current block. Fast In fast mode, which is the default so no flag is required, it can take a bit of time. It gets the block headers, the block bodies, it processes no transactions until current block - 64(*). Then it gets a snapshot state and goes like a full synchronization > geth For me it took 1 hr to download 60% of the blockchain but the remaining 40% took another 5 hrs. It currently takes ~120 Gb of HDD.   Full Fully mode will take over 1Tb in storage and will take forever to sync. Currently sync’ing so TBA.   The specs of my laptop is: The Internet connection was around 50Mb/s (Wireless home fibre)   Ref: https://ethereum.stackexchange.com/questions/11297/what-is-geths-light-sync-and-why-is-it-so-fast
Read More ›

Raspberry Pi 3, Node and Ethereum

March 6, 2018
0
8685
0
Ever wanted to receive payment with a cryptocurrency and then enable an action such as open a door or turn on a light? Here is a quick overview of how this can be done with Ethereum, a Raspberry Pi and Nodejs. Summary The idea is to display a QR code on a tablet where payments can be made with crypto and upon receipt of payment an LED is turned on. The webpage is running on a Raspberry Pi which is also running geth which is the Ethereum blockchain client. The neat thing is that there is an experimental “light” sync mode that only obtains the current blockchain state and only requires ~400Mb of disk space. See it in action In the video above I use Metamask to make the test ether payment. It takes about 30 seconds for the transaction to be acknowledge and the LED to light up. Html Payment Page The payment page basically consists of a QR code for the user to make a crypto payment and in the background, it connects to the local Ethereum blockchain to get the current balance and to listen for the next block to arrive. When it does, it queries the […]
Read More ›

How to run Ethereum on a Raspberry Pi 2

March 2, 2018
1
7892
0
Interested in getting Ethereum running on a Raspberry Pi 2? Here are some simple steps: Step 1: You get, I get, We get >> wget https://gethstore.blob.core.windows.net/builds/geth-linux-arm7-1.8.1-1e67410e.tar.gz Of course this means you know what wget is (a way to download files using cmd) and you have already ssh’d into your raspberry pi with something like ssh pi@192.168.x.x Where did this link come from? It came from https://geth.ethereum.org/downloads/ Search for Linux -> armv7 for the Raspberry Pi 2 and you’ll find the link. This is important to know because you’ll want to change the link to retrieve the latest binary. Step 2: Lay down the tar-seal and zip it up >> tar -xvf geth-linux-arm7-1.8.1-1e67410e.tar.gz The file downloaded is a tar or a “Tape Archive” in reference to the good old days when files would be put on “tapes” and then archived for storage. It is also known as a tarball. It stores multiple files together as a single file. gz  stands for GNU zip which compresses it. This is the equivalent of Winzip in the windows world. The x flag extracts it, v stands for verbose output, telling the user what is happening in more details and f tells tar to use the file […]
Read More ›

CustomContracts is not defined at

February 20, 2018
0
7861
0
Trying to delete a contract in Mist and getting this error? VM659:1 Uncaught ReferenceError: CustomContracts is not defined at <anonymous>:1:1 There is a work around you’ll find useful. Right click in the Contracts window and click Open developers tools. It should have an autocomplete and you should be able to run CustomContracts.find().fetch(). Expand an object, grab the _id and run CustomContracts.remove(“put_id_here”)  
Read More ›

Connecting Geth to MetaMask and Mist

February 8, 2018
0
8142
1
If you have geth, the Go Ethereum client running and you want to connect Mist or MetaMask to you get a nice front end, here is how you do it. Start geth with: > geth --datadir ./chaindata init ./myGenesisFile.json Note: If you don’t have a genesis file, one is provided at the end. The run > geth --datadir ./chaindata --networkid 1994 to spin up the private Ethereum blockchain Mist The easiest way to connect Mist to this private blockchain is to start it via command line and passing in the location of the ipc file with the rpc flag. > ./Mist --rpc /Users/cloudnthings/privatechain/chaindata/geth.ipc You should get the word PRIVATE-NET at the top. Click Launch Application and you should be away. If you get this error: NCAUGHT EXCEPTION { Error: connect ENOENT Users/cloudnthings/privatechain/chaindata/geth.ipc Then it means you have your syntax wrong. The most common mistake is not having a double dash before rpc (- – rpc) MetaMask To connect to MetaMask, you need to start the private Ethereum blockchain with an extra rpc flag. > geth --datadir ./chaindata --networkid 1994 --rpc You can connect to the blockchain as per normal via geth attach like so: > geth attach http://127.0.0.1:8545 or in MetaMask, simple choose localhost […]
Read More ›

What is Geth?

January 23, 2018
6
14996
0
Understanding how to download and interact with the Ethereum blockchain is a crucial part for anyone learning Ethereum. There are several popular clients to work with the Ethereum blockchain. They are: eth – a client written in C++ geth – a client written in Go pyethapp – a client written in python There’s also Haskell and Java. There is a more detailed description here. Here we will focus on Geth. What is Geth? Geth is a multipurpose command line tool that runs a full Ethereum node implemented in Go. It offers three interfaces: the command line subcommands and options, a Json-rpc server and an interactive console. Downloading Geth There are several ways to download Geth. One is to visit https://geth.ethereum.org/downloads/ and download the latest version suitable for your OS. Another option is to use brew for OSX users. Follow the instructions here. With brew, the steps are essentially: brew tap ethereum/ethereum brew install ethereum What this does is install the geth client at /usr/local/Cellar/ethereum/1.7.3/bin Then you can go to your terminal and run >> geth When you run this command, geth will start downloading the entire blockchain onto your laptop. The location of the chaindata will be shown in the terminal window. […]
Read More ›

Smart contract workshop #2: Remix and MetaMask

January 14, 2018
0
7004
0
It was great to see the dedicated ones turned up yesterday on a beautiful Saturday morning to learn about MetaMask and Remix and deploy a hello world smart contract. We went through the following topics: Install MetaMask Get some test ether Mixing it up with Remix Hello World Compile and deploy captain! Interactive with your smart contract Understanding the code Bonus code It really was about downloading and installing MetaMask, getting some test ether, opening Remix and deploying 4 lines of code and seeing the contract on the Etherscan. It was great to see some new faces and hopefully the learning by doing is helping those who actually want to get a better understanding of what this technology can do. Next week we’ll be looking at MyEtherWallet (MEW) and also creating professional paper wallets on photographic paper with holographic stickers as souvenirs or gifts or just if you want something physical to tuck under your mattress. There will be a catch up meetup on Tuesday 5:30pm for the city folks. Details of that can be found at: https://www.meetup.com/smartcontracts/events/246629747/ If you missed the meetup but want to check out the topics, visit: https://blockchains.learndot.com/ and connect with us on Telegram: https://t.me/joinchat/G84KThDRZaXOJsxa7oQHmw Catch everyone next week.
Read More ›

Hello World Ethereum Smart Contract

January 4, 2018
0
6895
1
Introduction There are lots of simple Ethereum Hello World tutorials around to cater for everyone’s level. This tutorial builds on a 2016 version by Karl Floersh and attempts to keep things very simple. All that is required to be installed is Meta Mask which is currently a Chrome only plugin and is essentially an Ethereum light client browser plugin. More formally: “MetaMask is a bridge that allows you to visit the distributed web of tomorrow in your browser today. It allows you to run Ethereum dApps right in your browser without running a full Ethereum node.“ Outcome To deploy a hello world smart contract on the Ethereum network. Here is the code. It’s 1 contract consisting of 1 function and 1 event. contract HelloWorld { event log_string(bytes32 log); // Event function () { // Fallback Function log_string("Hello World!"); } } This guide should only take about 10 minutes to follow. Step 1: Install MetaMask In Chrome, search for MetaMask and install it as a plugin. Then create an account and change the network to Ropsten. This is the test network. In order to get some test ether, click “BUY” and click “Ropsten test Faucet”. This will take you to https://faucet.metamask.io/ […]
Read More ›