<?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 quijano flores on Medium]]></title>
        <description><![CDATA[Stories by quijano flores on Medium]]></description>
        <link>https://medium.com/@quijanoflores?source=rss-7c57f2d51f60------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QzxhCFokTmLQmlmM.</url>
            <title>Stories by quijano flores on Medium</title>
            <link>https://medium.com/@quijanoflores?source=rss-7c57f2d51f60------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 10:57:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@quijanoflores/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[Web3.js fundamentals — How to avoid 2 pitfalls]]></title>
            <link>https://medium.com/@quijanoflores/web3-js-fundamentals-how-to-avoid-2-pitfalls-5b68063505d7?source=rss-7c57f2d51f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b68063505d7</guid>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[quijano flores]]></dc:creator>
            <pubDate>Sat, 15 Jul 2017 20:59:02 GMT</pubDate>
            <atom:updated>2017-07-15T20:59:02.744Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve written my smart contracts in Solidity.</p><p>I’ve written my unit tests for my smart contracts using javascript and mocha.</p><p>I’ve deployed my contracts onto the Kovan testnet using remix.</p><p>Now what?</p><p>If you’ve gotten this far — congrats you’ve done something very cutting edge and are probably working on a very exciting project.</p><p>The next thing to do is to give your users an interface so they can interact with the contracts you’ve just deployed. One of the most popular ones right now is React and its easily portable to the Ethereum Blockchain with the web3.js library.</p><p>When allowing your users to use YOUR interface you should take some responsibility and check two things before using web3 to interact with your smart contracts.</p><p>web3.eth.at(contractAddress)</p><p>web3.at is supposed to take an address but it can actually take any kind of object. The pitfall to avoid is checking that you are actually passing in a valid contract address. If you don’t do this you’ll run into Invalid Address issues for instance when you call a function from you Contract object.</p><p>web3.eth.sendTransaction(address,{from:coinbase, amount:amount})</p><p>This a bigger pitfall that you should take more responsibility for. sendTransaction does not check that the address you’re inputing is a valid address. You can even pass an `undefined` object. If you pass in an undefined object and an amount in the sendTransaction function and your user signs the transaction, a new contract will be created and ether will be sent to that contract. Opps sorry you trusted my interface and now your ether went somewhere you didn’t intend it to.</p><p>Both pitfalls can be avoid by common javascript try, catch, if, else. Try to send a transaction check that the to and from address that is signing the transaction are valid if they aren’t throw an error, catch the error. Try to create a Contract object using a ContractFatory and an address, check if the address is valid, if it’s not throw an error, catch the error.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b68063505d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ethereum Development — Suggested learning path]]></title>
            <link>https://medium.com/@quijanoflores/ethereum-development-suggested-learning-path-e3fbe89111c3?source=rss-7c57f2d51f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3fbe89111c3</guid>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[quijano flores]]></dc:creator>
            <pubDate>Mon, 19 Jun 2017 13:58:08 GMT</pubDate>
            <atom:updated>2017-06-19T14:03:46.064Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the suggested learning path developed at <a href="http://jaaga.in/study">http://jaaga.in/study</a> during the 2016 Q4 and 2017 Q1 quarters. This was the path used to create the dApp — <a href="http://www.automte.com/">www.automte.com</a></p><p>proof of work/mining the nonce<br>private keys &amp; public keys<br>setting up a development environment</p><ul><li><a href="http://truffleframework.com/">Truffle Suite - Your Ethereum Swiss Army Knife</a></li><li><a href="https://truffle-box.github.io/">Truffle Box</a></li></ul><p>generating wallets<br>signing a transaction</p><p><a href="https://github.com/MetaMask/metamask-plugin">MetaMask/metamask-plugin</a></p><p>Writing automated tests for stmart contracts<br>Writing a smart contract<br>- basic data structures, uint, string, address<br>- mapping<br>- structs<br>- calls and writes<br>- modifiers<br>- public, private, internal functions<br>- throw<br>- events<br>Using libraries</p><p><a href="https://openzeppelin.org/">OpenZeppelin</a></p><p>Deploying the contract to the blockchain</p><p><a href="http://ethereum.github.io/remix/">http://ethereum.github.io/remix/</a></p><p>UI — Interacting with your smart contract using web3.js</p><p><a href="https://github.com/ethereum/web3.js/">ethereum/web3.js</a></p><p><a href="https://github.com/ethjs">https://github.com/ethjs</a></p><p>Upgrading your contracts<br> <a href="https://github.com/ConsenSys/smart-contract-best-practices#upgrading-broken-contracts">https://github.com/ConsenSys/smart-contract-best-practices#upgrading-broken-contracts</a></p><p>Online Tutorials</p><p>decypher.tv/series/ethereum-development</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3fbe89111c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up a Python Dev environment for Running Simulations with CoolProp and Refprop on Windows]]></title>
            <link>https://medium.com/@quijanoflores/setting-up-a-python-dev-environment-for-running-simulations-with-coolprop-and-refprop-on-windows-ede8f18d8c25?source=rss-7c57f2d51f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/ede8f18d8c25</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[refprop]]></category>
            <category><![CDATA[coolprop]]></category>
            <category><![CDATA[windows]]></category>
            <dc:creator><![CDATA[quijano flores]]></dc:creator>
            <pubDate>Fri, 21 Apr 2017 09:35:34 GMT</pubDate>
            <atom:updated>2017-04-21T09:35:34.090Z</atom:updated>
            <content:encoded><![CDATA[<p>Write up for a devops project for some hackers at the Constellation makerspace in Shenzen, China.</p><p># installers<br><a href="https://www.continuum.io/downloads">Anaconda</a> (get the python 3 version)<br><a href="http://landinghub.visualstudio.com/visual-cpp-build-tools">visual studio build tools</a> (get the 2015 version)<br><a href="https://www.nist.gov/srd/refprop">refprop</a> (buy the license)</p><p><a href="https://docs.continuum.io/anaconda/ide_integration#python-for-visual-studio-code">python for visual studio code</a> (optional)</p><p># Install Anaconda from the installer</p><p>open up the anaconda installer and install, if you have python already installed on your machine you might want to uninstall it</p><p># Install Visual Studio Build tools from the installer</p><p>open up VS Build tools and install</p><p># create a virtualenv</p><p>open up a terminal with `cmd` and then enter this command</p><pre>conda create --name heatpumpsim</pre><p># drop into virtal env</p><pre>activate heatpumpsim</pre><p># install CoolProp</p><pre>pip install CoolProp</pre><p># install refprop</p><p>with the installer install refprop</p><p># set the system env</p><p>go to environment variables in the windows explorer and add a new variable</p><p>Name: REFPROP<br>Value: C:\Program Files (x86)\REFPROP\REFPROP64.dll</p><p># add the HMX file to the fluids folder</p><p>add the updated hmx file to the fluids folder</p><p># troubleshooting</p><p>If you get a <em>Value Error: Could not load these fluids</em></p><p><a href="http://www.coolprop.org/coolprop/REFPROP.html">reference</a></p><p>It’s because your PATH to refprop is not set correctly, in your python file make sure that it is pointing to the right place.</p><pre>CP.set_config_string(CP.ALTERNATIVE_REFPROP_PATH, &#39;C:<strong>\\</strong>PATH_TO<strong>\\</strong>REFPROP<strong>\\</strong>&#39;)```</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ede8f18d8c25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Support for browser based wallets with truffle-box]]></title>
            <link>https://medium.com/@quijanoflores/support-for-browser-based-wallets-with-truffle-box-31f8e6d87360?source=rss-7c57f2d51f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/31f8e6d87360</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[consensys]]></category>
            <dc:creator><![CDATA[quijano flores]]></dc:creator>
            <pubDate>Fri, 24 Feb 2017 08:16:14 GMT</pubDate>
            <atom:updated>2017-07-15T20:56:52.688Z</atom:updated>
            <content:encoded><![CDATA[<p>UPDATE: In July 2017, the truffle team at <a href="https://medium.com/u/6c7078bf7b01">ConsenSys</a> released a set of official boxes <a href="http://truffleframework.com/boxes/">http://truffleframework.com/boxes/</a>, the react-auth and react-uport boxes support redux!</p><p>A reducer to pass web3 to components as a prop from the Redux store. repo can be found here, <a href="https://github.com/qjflores/truffle-box-browser-wallet">truffle-box-browser-wallet</a>.</p><p><a href="https://truffle-box.github.io/">Truffle-box</a> has recently published a set of truffle-webpack-react boilerplates that make it easy to create a smart contract application with a React user interface.</p><p>The boiler plates are fantastic and I am particularly excited about <a href="https://github.com/truffle-box/truffle-box-uport/">truffle-box-uport</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vW6TlfcXTdCEzjxzBmE6RQ.png" /></figure><p>Engaging with smart contracts through your smart phone is going to be a reality soon.</p><p>Authorising transactions with your finger print from your phone is so future.</p><p>While exploring these boilerplates, I noticed that the react components weren’t aware of my Metamask browser based wallet. The boilerplates ship with setting the provider to the truffle contracts to `localhost:8545`.</p><p>Adding a few lines of java script to the truffle-box will make components aware of the Metamask browser based wallet.</p><pre>import Web3 from &#39;web3&#39;</pre><pre>import truffleConfig from &#39;./../../truffle-config.js&#39;</pre><pre>var web3Location = `<a href="http://${truffleConfig.networks.development.host}:${truffleConfig.networks.development.port}`">http://${truffleConfig.networks.development.host}:${truffleConfig.networks.development.port}`</a></pre><pre>var web3Provided;<br>if (typeof web3 !== &#39;undefined&#39;) {                            <br>  // Use the browser based wallet provider.     <br>  // DEVELOPER NOTE: removing the next commented line will break the app<br>  // eslint-disable-next-line<br>  web3Provided = new Web3(web3.currentProvider)<br>} else {                                                      <br>  // DEVELOPER NOTE: What happens if the <br>  // user does not have a browser based wallet? What happens<br>  // if the Web3 object cannot be initialised with the httpProvider<br>  // given from the location in the truffle-config file?<br>  web3Provided = new Web3(new Web3.providers.HttpProvider(web3Location))<br>}</pre><p>This implementation works well with the <a href="https://github.com/truffle-box/truffle-box-react">truffle-box-react</a> boilerplate and web3Provided can be passed in as a prop to the App component. This implementation becomes cumbersome when the project manages state using Redux because the developer would have to insert this script in every component that wants to use the MetamaskInpageProvider for the smart contract instance.</p><h3>Pass the web3 object as a prop to the component through the Redux store</h3><p>For folks that are new to Redux, the <a href="https://egghead.io/courses/getting-started-with-redux">egghead video series</a> are excellent.</p><p>If we want a friendly way to make all of our components aware of the same web3 object we need to get web3 from the Redux store. In order for us to do that we’ll need a web3 reducer that will handle actions appropriately.</p><p>web3Reducer.js →reducer</p><pre>import Web3 from &#39;web3&#39;</pre><pre>const provider = new Web3.providers.HttpProvider(&#39;<a href="http://localhost:8545&#39;">http://localhost:8545&#39;</a>)<br>const web3 = new Web3(provider)</pre><pre>const initialState = {<br>  web3: web3<br>}</pre><pre>const web3Reducer = (state = initialState, action) =&gt; {<br>  if (action.type === &quot;WEB_3_INITIALIZE&quot;) <br>  {<br>    return Object.assign({}, state, {<br>      web3: action.payload<br>    })<br>  }<br>  return state<br>}</pre><pre>export default web3Reducer</pre><p>web3Init.js →presentation component</p><pre>import React, { Component } from &#39;react&#39;</pre><pre>class Web3Init extends Component {</pre><pre>componentDidMount(){<br>        this.props.onWeb3ComponentLoad()<br>  }<br>  render() {<br>    return(<br>    &lt;li className=&quot;pure-menu-item&quot;&gt;<br>    &lt;/li&gt;<br>      )<br>  }<br>}</pre><pre>export default Web3Init</pre><p>Web3InitContainer.js →container component</p><pre>import { connect } from &#39;react-redux&#39;<br>import Web3Init from &#39;./Web3Init&#39;<br>import { web3Initialize } from &#39;./Web3InitActions&#39;</pre><pre>const mapStateToProps = (state, ownProps) =&gt; {<br>  return {<br>    web3:state.web3<br>  }<br>}</pre><pre>const mapDispatchToProps = (dispatch) =&gt; {<br>  return {<br>    onWeb3ComponentLoad: (web3) =&gt; {<br>      dispatch(web3Initialize(web3))<br>    }<br>  }<br>}</pre><pre>const Web3InitContainer = connect(<br>  mapStateToProps,<br>  mapDispatchToProps<br>)(Web3Init)</pre><pre>export default Web3InitContainer</pre><p>Web3InitActions.js →actions</p><pre>import Web3 from &#39;web3&#39;</pre><pre>import truffleConfig from &#39;./../../truffle-config.js&#39;</pre><pre>var web3Location = `<a href="http://${truffleConfig.networks.development.host}:${truffleConfig.networks.development.port}`">http://${truffleConfig.networks.development.host}:${truffleConfig.networks.development.port}`</a></pre><pre>export const WEB_3_INITIALIZE = &#39;WEB_3_INITIALIZE&#39;<br>function web3Init(web3) {<br>  return {<br>  type:WEB_3_INITIALIZE,<br>  payload:web3 <br>  }<br>}</pre><pre>export function web3Initialize() {<br>  return function(dispatch) {<br>    var web3Provided;<br>    if (typeof web3 !== &#39;undefined&#39;) {                            <br>      // Use the browser based wallet provider.     <br>      // DEVELOPER NOTE: removing the next commented line will break the app<br>      // eslint-disable-next-line<br>      web3Provided = new Web3(web3.currentProvider)<br>    } else {                                                      <br>      // DEVELOPER NOTE: What happens if the <br>      // user does not have a browser based wallet? What happens<br>      // if the Web3 object cannot be initialised with the httpProvider<br>      // given from the location in the truffle-config file?<br>      web3Provided = new Web3(new Web3.providers.HttpProvider(web3Location))<br>    }<br>    dispatch(web3Init(web3Provided))</pre><pre>}<br>}</pre><p>Now that we have a reducer for web3, when you want to pass in web3 as a prop to a new component:</p><ol><li>Define web3 in your mapStateToProps function in your container component.</li></ol><pre>const mapStateToProps = (state, ownProps) =&gt; {<br>  return {<br>     web3: state.web3     <br>  }<br>}</pre><p>2. In your mapDispatchToProps of your container component, pass web3 into the function that you pass as a prop to your presentation component</p><pre>const mapDispatchToProps = (dispatch) =&gt; {<br>  return {<br>    onSignUpFormSubmit: (name, web3) =&gt; {<br>       event.preventDefault();</pre><pre>    dispatch(signUpUser(name, web3))<br>   }<br>  }<br> }</pre><p>3. In the presentation component, add web3 to the state within the constructor function.</p><p>4. Finally in your actions file use the web3 to set the provider</p><pre>const authentication = contract(AuthenticationContract)<br>authentication.setProvider(web3.currentProvider)</pre><p>Some things that I noticed after creating the reducer:</p><p>web3 does not dispatch to the store immediately after the window loads, it has to wait until the web3Init presentation component loads.</p><p>This error came up when Metamask is locked and I have not migrated the contracts to the blockchain. I was not able to replicate this again.</p><pre>Uncaught Error: Invalid JSON RPC response: {“id”:1,”jsonrpc”:”2.0</pre><p>This warning comes up</p><pre>warning.js:36 Warning: setState(…): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the Connect(HiddenOnlyAuth(Component)) component.</pre><p>I believe this is coming up now because web3 is being passed into the unmounted components that are toggled when the user signed up for the first time.</p><p>There is some buggy behavior:<br>When updating the user name and rejecting the transaction through metamask the ui updates the username, to the user it looks like their transaction went through. If you logout and log back in, you can see that no change was made to the contract.</p><p>The first time that the user signs up and rejects the transaction has app has the appropriate behavior, if the user has signed up already it allows them to sign up again.</p><p>After the first time the user signed up, if they try to sign up again and reject the transaction it looks like they’ve signed up again. The user name is the original name from the first signup.</p><p>This is the first reducer that I’ve created, so I’m very open to edits, feedback and suggestions. :D Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31f8e6d87360" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sending Ether Between Two Contracts]]></title>
            <link>https://medium.com/hackernoon/sending-ether-between-two-contracts-5ad8699805fe?source=rss-7c57f2d51f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ad8699805fe</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[quijano flores]]></dc:creator>
            <pubDate>Fri, 17 Feb 2017 10:16:51 GMT</pubDate>
            <atom:updated>2017-07-16T19:56:50.073Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is the real world application?</strong><br>We have Providers that provide services to people, such as internet, telephone, water, food and shelter. People who want to use these services can subscribe to these services. Providers can charge debts that Users owe for utilising the service. Users can clear their debts by sending ether to the Provider.</p><p>Providers have jobs that they keep track of in order to provide their services and hire staff to complete those jobs. Staff Users can get paid by withdrawing ether from the Provider.</p><p>This post will cover the engagement of a Staff user completing a job and withdrawing ether from the Provider contract in order to help provide clarity around Invalid JUMP errors with sending ether to a contract. We’ll use the Singularity Kitchen as an example. I’ll first present the tests and then smart contracts.</p><p>Disclaimer<br><strong> contracts are not audited and contain security flaws, do not use for any other purpose than learning.</strong></p><p>Tests</p><pre>it(&#39;init&#39;, function() {<br>    return Kitchen.new(&quot;SingularityKitchen&quot;, &quot;Healthy living for the next gen&quot;, {from:_owner})<br>      .then(function(kitchenContract) {<br>        if(kitchenContract.address){<br>          kitchen = kitchenContract;<br>        } else {<br>          throw new Error(&quot;no contract address&quot;);<br>        }<br>        return true;<br>      })<br>  })</pre><pre>it(&#39;pay-out-job&#39;, function(){<br>    var jobName = &quot;Single Customer Order&quot;;<br>    assert.equal(balance(kitchen.address), web3.fromWei(1100000000000000000,&quot;ether&quot;))<br>    return kitchen.payOutJob(staff.address, jobName, {from:_owner})<br>      .then(function(txHash){<br>        return kitchen.staffList(staff.address);<br>      })<br>      .then(function(staffInfo){<br>        //this is the payout stored in a struct<br>        assert.equal(staffInfo[2].toString(), 300000000000000000);<br>        return kitchen.collectPayout(staff.address, {from:_staff1})<br>      .then(function(txHash){<br>        return kitchen.staffList(staff.address);<br>      })<br>      .then(function(staffInfo){<br>        console.log(balance(kitchen.address))<br>        assert.equal(staffInfo[2].toString(), 0);<br>        assert.equal(balance(staff.address), web3.fromWei(300000000000000000, &quot;ether&quot;));<br>        assert.equal(balance(kitchen.address), web3.fromWei(800000000000000000, &quot;ether&quot;));<br>      })<br>    })<br>  })<br></pre><p>I’ll walk through these two tests here, the rest of tests for the contract can be found on the <a href="https://github.com/qjflores/singularity/tree/master/test">github repo</a>.</p><p>In ‘init’, we create a new instance of the Kitchen contract by using the new method with some arguments and data about who is sending this transaction. Creating a new instance of a smart contract returns the Smart Contract and we can check if the smart contract has an address, if it does then we set it to a global variable ‘kitchen’. If the contract does not have an address then we throw a new error.</p><p>In ‘pay-out-job’, we first check to see that the kitchen contract has ether to pay people. Then we try to call on the payOutJob function from the kitchen contract. It takes an address of a User contract and the jobName that was completed. This transaction is called upon by some kind of owner like an authorized user who is allowed to engage with the contract to pay people for completing jobs. Once the payoutjob function will return a txHash, we’re not going to do anything with the txHash, but we could console log it and see the data that it contains. We’re going to call on a public attribute of the contract ‘staffList’ which is a mapping data type so we’ll pass in the address of the User contract. Passing in the address of the User contract into staffList will return a struct data type that contains a field for storing information about the payout to the Staff User. We can access contents of the struct by calling upon them like elements in an array. StaffInfo[2] is a uint256 data type and we can call a toString method to get the amount to be paid to the User contract in Wei. Here we’re asserting that it is 300000000000000000 Wei or the rate of the “Single Customer Order” Job that is set in the Kitchen contract. When the Staff User is ready to collect their payout, they can call on the collectPayout function from the Kitchen contract. We get back a transaction hash and call on the staffList so that we can check that there has been a change in the struct. We check that the payout has been set to 0 and that the balances of both the Kitchen and the Staff contract have changed appropriately.</p><p>Smart Contracts</p><p>The two smart contracts that we need in order to provide autonomy for this engagement are a User contract and a Provider contract. I’m building off of these contract from this <a href="https://www.youtube.com/watch?v=m9Zb49RNGis">YouTube tutorial series</a> by Shlomi Zeltsinger.</p><pre>contract User {<br>  string public userName;<br>  address public owner;</pre><pre>mapping (address =&gt; Service) public services;</pre><pre>struct Service{<br>    bool active;<br>    uint lastUpdated;<br>    uint debt;<br>  }</pre><pre>function User(string _name) payable {<br>    userName = _name;<br>    owner = msg.sender;<br>  }</pre><pre>function payable {<br>  }</pre><pre>function registerToProvider(address _providerAddress){<br>    services[_providerAddress] = Service({<br>      active:true,<br>      lastUpdated: now,<br>      debt: 0<br>      });<br>  }</pre><pre>function setDebt(uint256 _debt){<br>    if(services[msg.sender].active){<br>      services[msg.sender].lastUpdated = now;<br>      services[msg.sender].debt += _debt;<br>      } else {<br>        throw;<br>      }<br>  }</pre><pre>function clearDebt() returns (bool result){<br>    if (services[msg.sender].active){<br>      services[msg.sender].lastUpdated = now;<br>      services[msg.sender].debt = 0;<br>    } else {<br>      throw;<br>    }<br>  }</pre><pre>function unsubcribe(address _providerAddress){<br>    if(services[_providerAddress].debt == 0){<br>      services[_providerAddress].active = false;<br>    } else {<br>      throw;<br>    }<br>  }</pre><pre>contract Provider {<br>  string public providerName;<br>  string public description;</pre><pre>mapping (address =&gt; staffUser) public staffList;<br>  mapping (bytes32 =&gt; Job) public jobs;</pre><pre>struct staffUser{<br>    bool active;<br>    uint lastUpdated;<br>    uint256 payout;<br>  }</pre><pre>struct Job {<br>    bytes32 name;<br>    uint256 rate;<br>  }</pre><pre>function Provider(string _name, string _description) {<br>    providerName = _name;<br>    description = _description;<br>  }</pre><pre>function setDebt(uint256 _debt, address _userAddress) {<br>    User person = User(_userAddress);<br>    person.setDebt(_debt);<br>  }</pre><pre>function recievePayment(address _userAddress) payable returns (bool result) {<br>    User person = User(_userAddress);<br>    person.clearDebt();<br>    return true;<br>  }</pre><pre>function addStaff(address _userAddress) {<br>    staffList[_userAddress] = staffUser({<br>      active:true,<br>      lastUpdated: now,<br>      payout: 0<br>      });<br>  }</pre><pre>function addJob(bytes32 _name, uint256 _rate) {<br>    jobs[_name] = Job({name:_name,rate:_rate});<br>  }</pre><pre>function updateJobRate(bytes32 _name, uint256 _rate){<br>    jobs[_name].rate = _rate; <br>  }</pre><pre>function payOutJob(address _userContractAddress, bytes32 _jobName){<br>    staffList[_userContractAddress].payout += jobs[_jobName].rate;<br>  }</pre><pre>function collectPayout(address _userContractAddress) {<br>    uint256 _amount = staffList[_userContractAddress].payout;<br>    staffList[_userContractAddress].payout = 0; <br>    if(!_userContractAddress.send(_amount)){<br>      throw;<br>    }<br>  }</pre><pre>}</pre><p>I’ll highlight some functions in the contracts that are relevant to this post. Here’s a really <a href="https://github.com/raineorshine/solidity-by-example/blob/master/send-eth.sol">helpful example</a> of sending ether.</p><p>In our test, the ‘staff’ variable is an instance of the User contract. The big function to highlight and the main reason for writing this code review is the payable function. This is a fallback function. A fallback function is a function that doesn’t run any anything. More about fallback functions can be found <a href="https://github.com/ConsenSys/Ethereum-Development-Best-Practices/wiki/Fallback-functions-and-the-fundamental-limitations-of-using-send()-in-Ethereum-&amp;-Solidity">here</a>.</p><p>If a contract is receiving ether it needs to have this fallback function otherwise you’ll receive an Invalid Jump error.</p><blockquote>invalid JUMP means you called code that didn’t exist, or there was an array out of bounds. Calling code that doesn’t exist can happen in many forms: 1) There’s no code at the address of your contract, for some reason, 2) you’re calling a contract function that isn’t actually available, 3) your contract is calling another contract or function that’s not available. The easiest way right now is to comment out code until the error goes away, then slowly let it back in until you figure out the correct line. The next big feature for Truffle will be getting stack traces for these messages. — Tim</blockquote><pre>function payable {<br>  }</pre><p>The payOutJob function takes an User contract address and the name of a job and all this function does is gets the payout field from the staffUser struct by calling on the staffList mapping using the User contract address and then updates the payout by getting the job rate field from the Job struct by calling on the jobs mapping using the jobName.</p><p>The collectPayout function takes a User contract address and sets a variable _amount to the payout field from the staffUser struct by calling on the staffList mapping using the User contract address. Then we update the payout field to 0 and then try to send the amount of ether to the user contract using ‘_userContractAddress.send(_amount)’. If we’re not able to send the ether, then throw will revert everything in our transaction and the payout field will remain unchanged.</p><p>Thanks <a href="https://medium.com/u/af24ca856119">Tim Coulter</a> and Nikita Fuchs for providing clarity on Invalid Jumps.</p><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a>family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp;sponsorship</a> opportunities.</blockquote><blockquote>To learn more, <a href="https://goo.gl/4ofytp">read our about page</a>, <a href="http://bit.ly/HackernoonFB">like/message us on Facebook</a>, or simply, <a href="https://goo.gl/k7XYbx">tweet/DM @HackerNoon.</a></blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ad8699805fe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/sending-ether-between-two-contracts-5ad8699805fe">Sending Ether Between Two Contracts</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>