<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by N F on Medium]]></title>
        <description><![CDATA[Stories by N F on Medium]]></description>
        <link>https://medium.com/@NicoFrega?source=rss-65ab5d985c4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by N F on Medium</title>
            <link>https://medium.com/@NicoFrega?source=rss-65ab5d985c4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 07:24:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@NicoFrega/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Verify Your Smart Contract Using Gist]]></title>
            <link>https://medium.com/coinmonks/verify-your-smart-contract-using-gist-a3152537a7a7?source=rss-65ab5d985c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3152537a7a7</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[etherscan]]></category>
            <category><![CDATA[rinkeby]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[N F]]></dc:creator>
            <pubDate>Sun, 20 May 2018 18:57:52 GMT</pubDate>
            <atom:updated>2018-05-24T21:19:06.926Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s see how you can verify your smart contract using a gist of your project. The process is extremely simple, but you will need a couple things:</p><ul><li>A working smart contract. Use your own or clone this <a href="https://github.com/NFhbar/verify-contract-example">repo</a>.</li><li>Some <a href="https://faucet.rinkeby.io/">Rinkeby ETH</a>.</li><li>A <a href="https://gist.github.com/">GitHub</a> account.</li></ul><p>For this example I am deploying a simple ballot smart contract; you can use this method for any project you have since the important part is really after the contract is deployed, however, if you would rather follow along you can clone this <a href="https://github.com/NFhbar/verify-contract-example">repo</a>.</p><h3>The Setup</h3><p>I use Truffle to write, test, and deploy my contracts, so make sure you have <a href="http://truffleframework.com/">Truffle</a> installed globally. Cool, the contract we are deploying is a simple ballot contract found <a href="https://github.com/NFhbar/verify-contract-example/blob/master/contracts/Ballot.sol">here</a>.</p><p>If you are following along with the example repo, simply run:</p><pre>$ npm install</pre><p>Otherwise, let’s get truffle ready to deploy, we are going to need the following packages:</p><pre>$ npm install --save-dev dotenv<br>$ npm install --save-dev ethereumjs-wallet<br>$ npm install --save-dev truffle-wallet-provider</pre><p>Great, let’s get our truffle.js file ready to deploy to Rinkeby:</p><pre>require(&#39;dotenv&#39;).config()<br>const Web3 = require(‘web3’)<br>const web3 = new Web3()<br>const WalletProvider = require(‘truffle-wallet-provider’)<br>const Wallet = require(‘ethereumjs-wallet’)</pre><pre>const rinkebyPrivateKey = new Buffer(process.env[‘RINKEBY_PRIVATE_KEY’], ‘hex’)<br>const rinkebyWallet = Wallet.fromPrivateKey(rinkebyPrivateKey)<br>const rinkebyProvider = new WalletProvider(rinkebyWallet, ‘<a href="https://rinkeby.infura.io/&#39;">https://rinkeby.infura.io/&#39;</a>)</pre><pre>module.exports = {<br> migrations_directory: ‘./migrations’,<br> networks: {<br>   development: {<br>   host: ‘localhost’,<br>   port: 9545,<br>   network_id: ‘*’ // Match any network id<br> },<br> rinkeby: {<br>   provider: rinkebyProvider,<br>   // You can get the current gasLimit by running<br>   // truffle deploy — network rinkeby<br>   // truffle(rinkeby)&gt; web3.eth.getBlock(“pending”, (error, result)    <br>   // console.log(result.gasLimit))<br>   gas: 6721975,<br>   gasPrice: web3.toWei(‘50’, ‘gwei’),<br>   network_id: ‘4’,<br>   }<br>  }<br>}</pre><p>We are deploying through Infura using truffle wallet provider and ethereumjs wallet. Now let’s create a .env file in the root directory with your private key for deploying, place your private key in that file:</p><pre>RINKEBY_PRIVATE_KEY=”MY_PRIVATE_KEY_GOES_HERE...&quot;</pre><p>Make sure you add this file to your .gitignore file to make sure you don’t accidentally publish your private key.</p><h3>Deploying the Contract to Rinkeby</h3><p>Time to deploy to rinkeby. First let’s get some test ETH from the <a href="https://faucet.rinkeby.io/">Rinkeby Faucet</a>. Now, let’s enter truffle develop environment:</p><pre>$ truffle develop</pre><p>Time to compile, migrate, and test locally to make sure we are good to go, run the following commands:</p><pre>truffle(develop)&gt; compile<br>...<br>..<br>.</pre><pre>truffle(develop)&gt; migrate<br>...<br>..<br>.</pre><pre>truffle(develop)&gt; test<br>...<br>..<br>.</pre><p>If they all succeed with no errors, we are ready to deploy. Exit truffle develop environment and in the terminal run the following command:</p><pre>$ truffle deploy --network rinkeby</pre><p>You should get an output that looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*du3VkNDpmceHC4XlrYFZtQ.png" /><figcaption>Contract deployed to Rinkeby.</figcaption></figure><h3>Verifying our Contract</h3><p>Head over to <a href="https://rinkeby.etherscan.io/">Rinkeby Etherscan</a> and search your newly deployed contract using the contract address from your console. You should see your contract on the network:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UW-8AWXbYefvL4QQ-iIuvQ.png" /><figcaption>Rinkeby deployed contract.</figcaption></figure><p>Cool. Now click the Code tab and click on Verify and Publish:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mcqpQzBSmuFKedND3h4X6w.png" /><figcaption>Verify Contract.</figcaption></figure><p>We are going to use the Fetch from Gist option. First we need to create a new Gist. In your GitHub account, click on your profile and select Your gists. You should see your gist profile:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CnSRQl8DWeBqI1xRHuF9lg.png" /><figcaption>Gists.</figcaption></figure><p>In the file name text box type the name of your contract including the extension and in the gist box copy/paste your contract code from your project. Make sure the contract is exactly the same as your contract file. If you are importing any files into your source code include the code directly in your gist. Mine looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Sg8aoRP6NwHd4g0XnKV-w.png" /><figcaption>Gist Contract.</figcaption></figure><p>Now click Create public gist. Sweet! Time to verify. Back to Etherscan click the Fetch from gist button and copy/paste your Gist id:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vA31aXeoZ7j8kZ5K9hJPvA.png" /><figcaption>Fetch from gist.</figcaption></figure><p>Click Continue and Etherscan should load your code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jfzlt0B2Ee15aYcoln2PTA.png" /><figcaption>Etherscan code.</figcaption></figure><p>Excellent, now type your contract name in the Contract Name box, select your compiler version, if you used Optimization select it. If your constructor was deployed using arguments Etherscan should have picked up the encoded parameters automatically. Time to verify!</p><p>Click Verify and Publish and give it a little time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yebaVnSLribMbIHsXqsLew.png" /><figcaption>Etherscan verifying.</figcaption></figure><p>After a few seconds your contract will be verified:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P93brT_ath_Mp2EdHiNwsw.png" /><figcaption>Etherscan verified.</figcaption></figure><p>Done!Now your contract is officially verified and accessible to anyone with the contract address:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YwdC0lJO3CwmJSTH7fTl7A.png" /><figcaption>Verified contract code.</figcaption></figure><p>That’s it! Here is the <a href="https://github.com/NFhbar/verify-contract-example">repo</a> for this example and the <a href="https://gist.github.com/NFhbar/fdd49001bf873fd3db3ed4429821f56b">gist</a> in case you want to give it a try!</p><p>Thank you very much for reading this post! If you found this post useful <strong>please clap on this article and make sure to follow me for more regular content</strong>, also check out my <a href="https://github.com/NFhbar">Github</a> as I regularly post sample code and projects. If you have any questions feel free to reply below this post or shoot me an email.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3152537a7a7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/verify-your-smart-contract-using-gist-a3152537a7a7">Verify Your Smart Contract Using Gist</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Avocado Network Token Faucet]]></title>
            <link>https://medium.com/coinmonks/avocado-network-token-faucet-94973204d288?source=rss-65ab5d985c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/94973204d288</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[solidity-tutorial]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[N F]]></dc:creator>
            <pubDate>Thu, 17 May 2018 03:09:56 GMT</pubDate>
            <atom:updated>2018-05-17T05:59:03.965Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*SjMEtNWlFZ6bnKBi59MmAA.jpeg" /><figcaption>Avocado Network</figcaption></figure><p>I recently worked on an <a href="https://github.com/OpenZeppelin/openzeppelin-solidity/tree/master/contracts/token/ERC20">erc20</a> token faucet for the <a href="https://github.com/AvocadoNetwork/governance">Avocado Network</a> and their <a href="https://etherscan.io/address/0xfa6f7881e52fdf912c4a285d78a3141b089ce859#code">AVO</a> token. The idea was to have a token faucet that would allow users to request AVO tokens and to set a time lock after a successful request. The requirements were as follow:</p><ul><li>Donators can send AVO to the smart contract</li><li>Users can call any of these methods:<br>get1000Avo() — to succeed the last call from that user must be at least 1 hour ago<br>get2000Avo() — to succeed, the last call from that user must be at least 2 hours ago<br>get5000Avo() — to succeed, the last call from that user must be at least 5 hours ago</li></ul><p>Let’s see how we implemented these requirements into a fully functional smart contract.</p><p>For the impatient here is the <a href="https://github.com/AvocadoNetwork/smart-contract-faucet">repo with all the code</a>.</p><h3>The Faucet Contract</h3><p>These requirements imply two things:</p><ul><li>the faucet should have an owner to be able to turn the faucet on/off</li><li>the faucet should accept ERC20 basic tokens</li></ul><p>To get started the contract inherits these two contracts from <a href="https://github.com/OpenZeppelin/openzeppelin-solidity.">Open Zeppelin</a>: <a href="https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ownership/Ownable.sol">Ownable.sol,</a> and <a href="https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC20/ERC20Basic.sol">ERC20Basic.sol</a>.</p><pre>import “./token/ERC20Basic.sol”;<br>import “./ownership/Ownable.sol”;</pre><p>Great, now we can easily use methods from these two contracts to build our faucet, but first let’s set some storage for later use:</p><pre> string public faucetName;<br> ERC20Basic public tokenInstance;<br> bool public faucetStatus;<br> mapping(address =&gt; uint256) status;</pre><p>Very simple, we have a name for the faucet instance, an instance of an ERC20 basic token, the status of the faucet, and a map for the requesting address and their time lock status.</p><p>Nice, let’s look at the constructor:</p><pre>constructor(address _tokenInstance, string _faucetName)<br> public<br> {<br>    tokenInstance = ERC20Basic(_tokenInstance);<br>    faucetName = _faucetName;<br>    faucetStatus = true;</pre><pre>    emit FaucetOn(faucetStatus);<br> }</pre><p>The constructor takes two parameters: the address of the already deployed token instance and the name of the faucet. It then uses the address to set an instance of an ERC20Basic token, sets the faucet name, turns the faucet on and emits a nice event.</p><p>Now we need to set some constants:</p><pre> uint256 constant oneKToken = 1000000000000000000000;<br> uint256 constant twoKToken = 2000000000000000000000;<br> uint256 constant fiveKToken = 5000000000000000000000;<br> uint256 constant oneHours = 1 hours;<br> uint256 constant twoHours = 2 hours;<br> uint256 constant fiveHours = 5 hours;</pre><p>Solidity provides units of <a href="http://solidity.readthedocs.io/en/v0.4.24/units-and-global-variables.html?highlight=time">time</a> which we can easily use to set the time lock period for each method. We also set the amount of tokens to be distributed by each function.</p><p>Let’s look at how the faucet functions will actually work; each function will follow the same logic:</p><ul><li>check the time lock status of the sender by accessing the status map</li><li>if the status is locked, then revert</li><li>if the status is not locked send the sender their tokens and updated their status</li><li>finally emit an event to let the world know what just happened</li></ul><p>Here is the general flow:</p><pre>function drip1000Token()<br> public<br> faucetOn()<br> {<br>     if(checkStatus(msg.sender)) {<br>         revert();<br>     }<br>     tokenInstance.transfer(msg.sender, oneKToken);<br>     updateStatus(msg.sender, oneHours);</pre><pre>     emit OneKTokenSent(msg.sender);<br> }</pre><p>First the function checks that the faucet is turned on, then we go into checking the time lock status of the sender:</p><pre>function checkStatus(address _address)<br> internal<br> view<br> returns (bool)<br> {<br>     //check if first time address is requesting<br>     if(status[_address] == 0) {<br>         return false;<br>     }<br>     //if not first time check the timeLock<br>     else {<br>          // solium-disable-next-line security/no-block-members<br>          if(block.timestamp &gt;= status[_address]) {<br>              return false;<br>          }<br>          else {<br>              return true;<br>          }<br>     }<br> }</pre><p>Note this function has the internal modifier. First we check if the sender is requesting for the first time, if they are, cool, let them have their tokens. Otherwise we check the status of their time lock by comparing it to the current block timestamp. If the block timestamp is less than their current lock time it means the time period has not yet passed and you can’t have tokens, otherwise you are good to go, we send you your tokens and then update your status:</p><pre>function updateStatus(address _address, uint256 _timelock)<br> internal<br> { // solium-disable-next-line security/no-block-members<br>     status[_address] = block.timestamp + _timelock;<br> }</pre><p>Which simply means setting your time lock to be the current block timestamp plus the required waiting period, in this case 1 hour.</p><p>Here is the full contract code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e37d3da5ce22e7bbb1ef0a691cdccd13/href">https://medium.com/media/e37d3da5ce22e7bbb1ef0a691cdccd13/href</a></iframe><p>Nice, time to write some tests.</p><h3>Testing the Faucet</h3><p>Of course we used <a href="http://truffleframework.com/">Truffle</a> for developing, so we have a nice testing suite available. Let’s look at one of the tests that checks the drip1000Token() function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3111527c5dba4148e450f45a4dd1001/href">https://medium.com/media/f3111527c5dba4148e450f45a4dd1001/href</a></iframe><p>First we get the artifacts we will need to test, then we pick up some nice helpers from <a href="https://github.com/OpenZeppelin/openzeppelin-solidity/tree/master/test/helpers">Open Zeppelin</a>. We make sure to deploy the contracts before the test in the beforeEach block.</p><p>For the actual test, first we send some AVO tokens to the contract:</p><pre>//Donor sends AVO to faucet await AVO.transfer(faucet.address, amount, { from: accounts[1] }) faucet_balance = await AVO.balanceOf.call(faucet.address, { from: accounts[0] }) assert.equal(faucet_balance.toNumber(), amount)</pre><p>We then have an address ask for 1000 AVO tokens:</p><pre>//Sends 1000 AVO to requesting address<br> confirm = await faucet.drip1000Token({from: accounts[0]})<br> faucet_balance = await AVO.balanceOf.call(faucet.address, { from: accounts[0] })<br> assert.equal(faucet_balance.toNumber(), amount — drip)<br> sender_balance = await AVO.balanceOf.call(accounts[0], { from: accounts[0] })<br> assert.equal(sender_balance.toNumber(), drip)</pre><p>Can this sender request again? Nope:</p><pre>//check previous sender is now locked from requesting again<br> await assertRevert(faucet.drip1000Token({from: accounts[0]}))</pre><p>Let’s now travel forward 1 hour in time to see if the sender can get more tokens:</p><pre>//advancing 1 hour in time<br> const unlockTime = latestTime() + duration.hours(1)<br> await increaseTimeTo(unlockTime)</pre><p>Get me more AVO!</p><pre>//previous sender can now request again<br> confirm = await faucet.drip1000Token({from: accounts[0]})<br> faucet_balance = await AVO.balanceOf.call(faucet.address, { from: accounts[0] })<br> assert.equal(faucet_balance.toNumber(), 0)<br> sender_balance = await AVO.balanceOf.call(accounts[0], { from: accounts[0] })<br> assert.equal(sender_balance.toNumber(), 2*drip)</pre><p>We are good to go!</p><p>Head over to the faucet repo to get the <a href="https://github.com/AvocadoNetwork/smart-contract-faucet/tree/master/test">full test suite</a>.</p><h3>Release</h3><p>The faucet was released as <a href="https://github.com/NFhbar/smart-contract-faucet/releases">v2.0.0</a> which you can get on <a href="https://www.ethpm.com/registry/packages/48">ethpm</a>, or simply fork/clone the <a href="https://github.com/AvocadoNetwork/smart-contract-faucet">repo</a>.</p><p>That’s it! If you would rather work on this contract in <a href="http://remix.ethereum.org/">Remix</a>, I set up a <a href="https://gist.github.com/NFhbar/e2112d0d909881e5c82b2c3d6a1c5e75">Gist</a> you can use.</p><p>Shout out to the <a href="https://github.com/AvocadoNetwork">Avocado Network</a>, <a href="https://github.com/peter-evans">Peter Evans</a>, and <a href="https://github.com/agro1986">agro1986</a> for crucial contributions and review.</p><p>Thank you very much for reading this post! If you found this post useful <strong>please clap on this article and make sure to follow me for more regular content</strong>, also check out my <a href="https://github.com/NFhbar">Github</a> as I regularly post sample code and projects. If you have any questions feel free to reply below this post or shoot me an email.</p><p>Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94973204d288" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/avocado-network-token-faucet-94973204d288">Avocado Network Token Faucet</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sign an Ethereum transaction off-line]]></title>
            <link>https://medium.com/coinmonks/sign-an-ethereum-transaction-off-line-d3e38fbda677?source=rss-65ab5d985c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3e38fbda677</guid>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[web3-tutorial]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[N F]]></dc:creator>
            <pubDate>Fri, 30 Mar 2018 19:12:13 GMT</pubDate>
            <atom:updated>2020-10-16T11:22:14.076Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post we will look at how to sign an Ethereum transaction off line using <a href="https://github.com/ethereumjs/ethereumjs-tx">ethereumjs-tx</a> and <a href="https://nodejs.org/en/">Node.js</a>. Repo available <a href="https://github.com/NFhbar/nodeJS-ETH-transaction">here</a>.</p><h3>Set up your local instance</h3><p>Clone the <a href="https://github.com/NFhbar/nodeJS-ETH-transaction">repo</a> to your local machine:</p><pre>git clone git@github.com:NFhbar/nodeJS-ETH-transaction.git</pre><p>Install it:</p><p>$ npm install</p><p>You are also going to need <a href="http://truffleframework.com/ganache/">Ganache</a>.</p><h3>Sending Ether</h3><p>Let’s see how this works. First start your local Ganache instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Wfmj_meoPjXEmQs_1uhUg.png" /><figcaption>First couple blocks in Ganache.</figcaption></figure><p>After starting Ganache you should see blocks starting to populate. I set my block time to 3 seconds but you can set it to whatever you like.</p><p>Next up let’s start the node menu, cd into your project folder and:</p><pre>$ npm run start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eLYmiRobYeIeqswc7KNSMg.png" /><figcaption>Node.js menu.</figcaption></figure><p>Great! Let’s try to send a transaction now. Press 1 to send Ether from one Ganache account to another:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oqNsMMX9KJAyLNm_fjHb9A.png" /><figcaption>Send Ether receipt.</figcaption></figure><p>If you get this screen it means that the transaction was successfully sent! You are seeing the receipt of your transaction which includes block hash, transaction hash, gas used, etc.</p><p>You can also inspect your transaction in Ganache:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wRGck17JlTHOirNKqcdXwA.png" /><figcaption>Ganache showing tx.</figcaption></figure><p>Click on the transaction for more details:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e2gQ9nAbq4VFNI1aZIWROg.png" /><figcaption>Ganache tx details.</figcaption></figure><p>Cool, let’s look at the code.</p><h3>Sign Transaction Off-line</h3><p>The heavy lifting is done by <a href="https://github.com/ethereumjs/ethereumjs-tx">ethereumjs-tx</a> which allows you to easily create raw transactions, sign them, and serialize them. Let’s go over the logic.</p><p>First we need web3 to connect to the local Ganache instance:</p><pre>import Web3 from &#39;web3&#39;;</pre><pre>var web3 = new Web3(new Web3.providers.HttpProvider(&#39;<a href="http://127.0.0.1:7545&#39;">http://127.0.0.1:7545&#39;</a>));</pre><pre>export default web3;</pre><p>We can now import our web3 instance anywhere we need to use it.</p><p>Next let’s look at how the transaction is prepared and sent:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15c405566d9af0d6d4eef7e1552a2cc0/href">https://medium.com/media/15c405566d9af0d6d4eef7e1552a2cc0/href</a></iframe><p>There are three imports:</p><ul><li>Ganache connected instance of web3</li><li>accounts from our accounts file</li><li>transaction builder file to pass our transaction data</li></ul><p>Our function then gets all the required values for our transaction: estimate gas, gas price, transaction count, etc. The amount to send is set to 20 eth but you could easily set it to be dynamically accepted by the menu if you like. We then build a transaction data structure and pass it to our transaction builder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90801054c2b065d3d520e62c2ff60f56/href">https://medium.com/media/90801054c2b065d3d520e62c2ff60f56/href</a></iframe><p>There are three imports:</p><ul><li>Ganache connected instance of web3</li><li>Tx instance from ethereumjs-tx</li><li>dotenv for our private key</li></ul><p>We grab our private key via:</p><pre>var privateKey = new Buffer(process.env[&quot;PRIVATE_KEY&quot;], &quot;hex&quot;);</pre><p>then we get set our values to hex using the web3 util:</p><pre>const nonceHex = web3.utils.toHex(nonce);<br>const valueHex = web3.utils.toHex(value);<br>const limitHex = web3.utils.toHex(gasLimit);<br>const priceHex = web3.utils.toHex(gasPrice);</pre><p>Now we can build a raw transaction object:</p><pre>switch (method) {<br>    case &#39;sendEther&#39;:<br>    rawTx = {<br>      nonce: nonceHex,<br>      gasPrice: priceHex,<br>      gasLimit: limitHex,<br>      to: toAddress,<br>      value: valueHex<br>    };<br>    break;<br>  }</pre><p>You can add more cases for any transaction you like to perform.</p><p>Finally, we can sign our transaction and return it for sending:</p><pre>var tx = new Tx(rawTx);<br>tx.sign(privateKey);<br>var serializedTx = tx.serialize();</pre><pre>return serializedTx;</pre><p>Great, now we can simply send it via the web3 method:</p><pre>await web3.eth.sendSignedTransaction(&#39;0x&#39; + rawTx.toString(&#39;hex&#39;));</pre><p>And that’s it! As you can see <a href="https://github.com/ethereumjs/ethereumjs-tx">ethereumjs-tx</a> is an awesome little module.</p><p>Thank you very much for reading this post! If you found this post useful <strong>please clap on this article and make sure to follow me for more regular content</strong>, also check out my <a href="https://github.com/NFhbar">Github</a> as I regularly post sample code and projects. If you have any questions feel free to reply below this post or shoot me an email.</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><p>Happy coding!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F41d817%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F41d817%2F&amp;image=https%3A%2F%2Fe.enpose.co%2F%3Fkey%3DdRXnS9Gplk%26w%3D700%26h%3D425%26url%3Dhttps%253A%252F%252Fupscri.be%252F41d817%252F%253Fenpose&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/1392d91b5a75cd2a4d61f9e47610b9f2/href">https://medium.com/media/1392d91b5a75cd2a4d61f9e47610b9f2/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3e38fbda677" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/sign-an-ethereum-transaction-off-line-d3e38fbda677">Sign an Ethereum transaction off-line</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy ERC20 Token]]></title>
            <link>https://medium.com/coinmonks/erc20-token-deployer-fd4b544598ab?source=rss-65ab5d985c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd4b544598ab</guid>
            <category><![CDATA[truffle]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[smart-contracts-tutorial]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[N F]]></dc:creator>
            <pubDate>Fri, 09 Mar 2018 19:29:50 GMT</pubDate>
            <atom:updated>2020-10-16T11:04:42.902Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post we‘ll go over an erc20 token factory contract that deploys a token with a single click. The dapp is built with <a href="https://reactjs.org/">React</a>, <a href="http://truffleframework.com/docs/">Truffle</a>, <a href="http://truffleframework.com/docs/drizzle/getting-started">Drizzle</a>, <a href="https://metamask.io/#how-it-works">Metamask</a>, and <a href="https://github.com/OpenZeppelin/zeppelin-solidity">Zeppelin-Solidity</a>. Repo available <a href="https://github.com/NFhbar/Token-Deployer">here</a>.</p><h3><strong>Rinkeby Factory Instance</strong></h3><p>A factory instance deployed to Rinkeby test net is available <a href="https://one-click-token.herokuapp.com/">here</a> — you need to have Metamask installed and need to be connected to Rinkeby network.</p><p>The UI is very simple:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dFmkird42AcQ0shzMzmH3g.png" /><figcaption>Token Deployer UI.</figcaption></figure><p>For the dapp to work properly you need to:<br>- Make sure you have Metamask <a href="https://metamask.io/#how-it-works">installed</a><br>- Select Rinkeby Test Network<br>- Make sure you have some <a href="https://faucet.rinkeby.io/">test ETH</a> in your account</p><p>Metamask injects <a href="https://web3js.readthedocs.io/en/1.0/">Web3</a> and the account you are using is displayed. The form accepts two parameters: your <em>Token Name</em> and your <em>Token Symbol</em>. For simplicity the total supply is hard-coded to be:</p><pre>uint8 public constant decimals = 18;</pre><pre>INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals));</pre><p>After typing your token name and symbol hit the button and Metamask will ask for confirmation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_c94CQt2kIOHHTCWRec1hw.png" /><figcaption>Metamask waiting for confirmation.</figcaption></figure><p>After you confirm your transaction it will be submitted, mined, and then the UI will update:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TxE6Z_4EpZTHXH--WduZvw.png" /><figcaption>Token successfully deployed.</figcaption></figure><p>The dapp shows a message indicating the transaction was successfully submitted and it updates the footer with your token contract address and the transaction hash, you can verify this using <a href="https://rinkeby.etherscan.io/">Etherscan</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1iSJPMHzRzFsHyDs9Y_fpA.png" /><figcaption>Transaction success in Etherscan.</figcaption></figure><p>Now simply use your token contract address to add your token to your Metamask:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ttxCf1avnUG83fkrrO0_CA.png" /><figcaption>Add your new token to Metamask.</figcaption></figure><p>That’s it! You can now send your new token to anyone!</p><h3>Token Factory</h3><p>The token contract is a simple modification of Zeppelin-Solidity’s erc20 standard token:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/886367a8bc43c56f1b9759465eba6f4a/href">https://medium.com/media/886367a8bc43c56f1b9759465eba6f4a/href</a></iframe><p>For simplicity purposes the INITIAL_SUPPLY is set to be a fixed value but you could simply pass it as an extra constructor parameter if you like. The constructor takes the _name and _symbol variables and allocates them, finally the total supply is sent to the _owner.</p><p>The token factory contract is given by:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f711d99c3da1471b39d2588f417d28fd/href">https://medium.com/media/f711d99c3da1471b39d2588f417d28fd/href</a></iframe><p>The constructor creates a new MyToken instance and sets the appropriate parameters. MyTokenFactory inherits methods from <a href="https://gist.github.com/NFhbar/ce4b22d5fc3a65559f694ab3bf9ab418">Factory.sol</a> like register.</p><p>That’s it! If you would like to work on this dapp or make suggestions <a href="https://github.com/NFhbar/Token-Deployer">here is the repo</a> and the <a href="https://one-click-token.herokuapp.com/">Heroku dapp</a>.</p><p>Thank you very much for reading this post! If you found this post useful <strong>please clap on this article and make sure to follow me for more regular content</strong>, also check out my <a href="https://github.com/NFhbar">Github</a> as I regularly post sample code and projects. If you have any questions feel free to reply below this post or shoot me an email.</p><p>Happy coding!</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd4b544598ab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/erc20-token-deployer-fd4b544598ab">Deploy ERC20 Token</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Payroll Smart Contract on Ethereum]]></title>
            <link>https://medium.com/coinmonks/payroll-smart-contract-on-ethereum-ae536e49403d?source=rss-65ab5d985c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae536e49403d</guid>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[truffle]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[N F]]></dc:creator>
            <pubDate>Fri, 02 Mar 2018 18:04:35 GMT</pubDate>
            <atom:updated>2020-10-16T10:40:43.397Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9k7Diqh5TMnnEAC3FWqrw.jpeg" /></figure><p>In this post we’ll go over a Payroll smart contract written in <a href="https://solidity.readthedocs.io/en/develop/">Solidity</a> using <a href="http://truffleframework.com/">Truffle</a> and <a href="https://github.com/OpenZeppelin/zeppelin-solidity">Open Zeppelin</a>. You can find the repo <a href="https://github.com/NFhbar/payroll">here</a>.</p><p>Let’s make sure you have Truffle installed globally:</p><pre>$ npm install -g truffle</pre><p>Clone my <a href="https://github.com/NFhbar/payroll">repo</a> to your local machine and install:</p><pre>$ npm install</pre><p>You can now use Truffle develop to compile, migrate, and run the tests:</p><pre>$ truffle develop<br>truffle(develop)&gt; compile<br>truffle(develop)&gt; migrate<br>truffle(develop)&gt; test</pre><p>Ok, enough of that, let’s look at some code.</p><p>The contract follows an interface approach similar to Zeppelin’s <a href="https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/ERC20/ERC20.sol">ERC20</a> standard in which an interface contract is defined. In our case the Payroll interface is given by:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/320d15c037a49b9719f685038e4be003/href">https://medium.com/media/320d15c037a49b9719f685038e4be003/href</a></iframe><p>You can see that we have all the functions necessary to manage employees and payments. Now, let’s look at the main contract: <a href="https://github.com/NFhbar/payroll/blob/master/contracts/Payroll.sol">Payroll.sol</a>.</p><p>Payroll.sol has three imports:</p><pre>import &#39;./InterfacePayroll.sol&#39;;<br>import &#39;./EmployeeStorage.sol&#39;;<br>import &#39;./EmployeeToken.sol&#39;;</pre><p>which allow to set the Storage variables:</p><pre>/*<br>*  Storage<br>*/<br>InterfaceEmployeeStorage public employeeStorage;<br>EmployeeToken public employeeToken;</pre><p>EmployeeStorage.sol defines the employee structure:</p><pre>/*<br>*  Storage<br>*/<br>struct Employee {<br>     bool exists;<br>     uint256 id;<br>     address accountAddress;</pre><pre>     address tokenContractAddress;<br>     uint256 latestPayday;<br>     uint256 monthlySalary;<br>}</pre><p>EmployeeToken.sol is a simple ERC20 standard contract:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b439b71223b184d4b266d69a30f7ccf/href">https://medium.com/media/7b439b71223b184d4b266d69a30f7ccf/href</a></iframe><p>The constructor for Payroll.sol is given by:</p><pre>/*<br>* Public functions<br>*/<br>/// <a href="http://twitter.com/dev">@dev</a> Contract constructor sets storage and token.<br>function Payroll()<br>    public<br>{<br>   setEmployeeStorage(new EmployeeStorage());<br>   setEmployeeToken(new EmployeeToken());<br>}</pre><p>which simply sets the employee storage and the employee token. The contract owner can now manage the employees through any of the functions defined in InterfacePayroll.sol. Employees can request to be payed for a given pay period by calling:</p><pre>/// <a href="http://twitter.com/dev">@dev</a> allows employee to get payed.<br>/// <a href="http://twitter.com/param">@param</a> _payPeriod of requested payment.<br>function getPay (uint256 _payPeriod)<br>      public<br>      employeePayPeriodExists(_payPeriod)<br>      enoughTokensLeft()<br>{<br>      uint256 employeeSalary =        employeeStorage.getMonthlySalary(msg.sender);<br>      employeeToken.transfer(msg.sender, employeeSalary);</pre><pre>        uint256 newPayday = employeeStorage.getLatestPayday(msg.sender);<br>        newPayday++;<br>        employeeStorage.setlatestPayday(msg.sender, newPayday);<br>        EmployeePayed(msg.sender, newPayday--);</pre><pre>}</pre><p>Payroll.sol also has several events for dapp watching:</p><pre>/*<br>*  Events<br>*/<br>event Deposit(address indexed sender, uint value);<br>event NewEmployee(address indexed newEmployee);<br>event EmployeeAddressChange(address indexed newAddress);</pre><pre>event EmployeePaydayChange(address indexed employeeAddress, uint indexed newPayday);</pre><pre>event EmployeeSalaryChange(address indexed employeeAddress, uint indexed newSalary);</pre><pre>event EmployeeRemoved(address indexed employeeAddress, uint indexed_id);</pre><pre>event EmployeePayed(address indexed employeeAddress, uint payPeriod);</pre><p>Right now the pay period is set to be simply an uint , but it could easily be set to an actual time frame as specified by the owner.</p><p>That’s it! If you would rather work on this contract in <a href="http://remix.ethereum.org/">Remix</a>, I set up a <a href="https://gist.github.com/NFhbar/15a80e5785080e499099581799d3b5f2">Gist</a> you can use.</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><p>Thank you very much for reading this post! If you found this post useful <strong>please clap on this article and make sure to follow me for more regular content</strong>, also check out my <a href="https://github.com/NFhbar">Github</a> as I regularly post sample code and projects. If you have any questions feel free to reply below this post or shoot me an email.</p><p>Happy coding!</p><figure><a href="http://bit.ly/2G71Sp7"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fKX2mtg7p1lOs7JmosPLsA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae536e49403d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/payroll-smart-contract-on-ethereum-ae536e49403d">Payroll Smart Contract on Ethereum</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>