<?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[VALUS - Medium]]></title>
        <description><![CDATA[Developer insight to Blockchain, Web, Cloud, Project Management… - Medium]]></description>
        <link>https://medium.com/valus?source=rss----bb07f462a264---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>VALUS - Medium</title>
            <link>https://medium.com/valus?source=rss----bb07f462a264---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 18:26:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/valus" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Forwarder contract for Ether and ERC-20 tokens]]></title>
            <link>https://medium.com/valus/forwarder-contract-for-ether-and-erc-20-tokens-e257a621889d?source=rss----bb07f462a264---4</link>
            <guid isPermaLink="false">https://medium.com/p/e257a621889d</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[exchange]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Primoz Kocevar]]></dc:creator>
            <pubDate>Wed, 21 Nov 2018 19:01:22 GMT</pubDate>
            <atom:updated>2018-11-23T21:26:17.967Z</atom:updated>
            <content:encoded><![CDATA[<h4>Generating address contracts for each user to transfer their Ether and ERC-20 tokens to one main wallet.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*HZjnfARjLLwGPYdgJZEZJw.png" /></figure><p>The final solution is presented in this GitHub repository:</p><p><a href="https://github.com/primozkocevar/SigWallet-ERC20">primozkocevar/SigWallet-ERC20</a></p><h3>Reformatting a different solution</h3><p>For this task code from this git repository was used and <strong>reformated</strong>:</p><p><a href="https://github.com/BitGo/eth-multisig-v2">BitGo/eth-multisig-v2</a></p><p>However already when just trying to call a <em>createForwarder()</em> function of a deployed <strong>WalletSimple</strong> contract there was a problem. A call to the contract was made by signing it locally like so:</p><pre>walletContract = web3.eth.contract(address=&quot;0xE81ab8f77a3Bbf2d19088D1d941270A2E3160825&quot;, abi=WalletSimple.ABI)<br><br>nonce = web3.eth.getTransactionCount(mainAccount.address)<br><br>tx = walletContract.buildTransaction({  <br>    &#39;from&#39;: mainAccount.address,<br>    &#39;gasPrice&#39;: web3.toWei(&#39;14&#39;, &#39;gwei&#39;),<br>    &#39;gas&#39;: 900000,<br>    &#39;nonce&#39;: nonce}).<strong>createForwarder</strong>()<br>signed = web3.eth.account.<strong>signTransaction</strong>(tx)<br>transaction_address = web3.eth.<strong>sendRawTransaction</strong>(signed.rawTransaction)<br>txReceipt = web3.eth.waitForTransactionReceipt(transaction_address)</pre><p>However after the transaction was processed the <em>txReceipt</em> did <strong>not</strong> contain an <strong>address</strong> of a produced forwarder, which is a <strong>crucial</strong> piece of information for sending funds. Although this was required in the <strong>solidity</strong> <strong>constructor</strong> of the <strong>WalletSimple</strong> contract like:</p><pre><strong>constructor</strong>() public returns (address) {<br> return new Forwarder();<br> }</pre><p>The reason this function did not return an address as specified is that this address is probably <strong>yet not</strong> <strong>defined</strong> the moment a constructor is called and thus can not be returned as the <strong>real</strong> network needs some time for this to process (this is probably why it <strong>worked</strong> testing on a <strong>local</strong> network).</p><h3>Let us fix it</h3><p>Thus a simple and quick fix was applied that admittedly consumes some additional gas. Adding <strong>two</strong> additional <strong>global</strong> <strong>variables</strong> was implemented.</p><p>A global variable is defined as soon as the constructor of Forwarder.sol is called so it is <strong>aware</strong> of its own address.</p><pre><strong>forwarderAddress</strong> = address(this);</pre><p>This one is the <strong><em>forwarderAddress</em></strong> in the Forwarder.sol contract itself and it is necessary so that it could be called from the WalletSimple contract to set it as a second global variable <strong><em>latestForwarder</em></strong> like so:</p><pre>Forwarder f = new Forwarder();<br> <strong>latestFowarder</strong> = f.forwarderAddress();</pre><p>Needless to say, these two global variables automatically get <strong>getters</strong> defined in Solidity so they can be called and their value is <strong>publicly</strong> <strong>accessible </strong>on the Ethereum main net.</p><p>Adding an additional line to the <strong>web3.py</strong> part when calling <strong>WalletSimple</strong> is crucial:</p><pre>walletContract = web3.eth.contract(address=&quot;0xE81ab8f77a3Bbf2d19088D1d941270A2E3160825&quot;, abi=WalletSimple.ABI)<br><br>nonce = web3.eth.getTransactionCount(mainAccount.address)<br><br>tx = walletContract.buildTransaction({  <br>    &#39;from&#39;: mainAccount.address,<br>    &#39;gasPrice&#39;: web3.toWei(&#39;14&#39;, &#39;gwei&#39;),<br>    &#39;gas&#39;: 900000,<br>    &#39;nonce&#39;: nonce}).createForwarder()<br>signed = web3.eth.account.signTransaction(tx)<br>transaction_address = web3.eth.sendRawTransaction(signed.rawTransaction)<br><strong>forwarderAddress = walletContract.functions.latestFowarder().call()</strong><br>txReceipt = web3.eth.waitForTransactionReceipt(transaction_address)</pre><p>Explanation: <em>we could not get the address through the constructor as on the real network an address of the deployed contract is not yet available at the same moment as constructor is called but a bit later, so that we have to get it via a global public variable of walletSimple contract named latestForwarder (a getter for this variable is simply called with () as any other function!</em></p><h4>EFFICIENCY?</h4><p>This approach is maybe not optimal as it consumes extra gas and the <em>latestForwarder</em> variable can be sensitive to multiple addresses calling it at once and could bring some <strong>unpredicted</strong> behaviour. Thus an approach mentioned in the <strong>documentation</strong> is also to be considered to more thoroughly refurbish mentioned contracts to return a correct address after the constructor:</p><p><a href="https://solidity.readthedocs.io/en/v0.4.24/contracts.html#creating-contracts">Contracts - Solidity 0.4.24 documentation</a></p><p>However, this approach <strong>did</strong> <strong>not</strong> <strong>work</strong> for us, thus the first recommended approach was still a good call we decided as we call fowarderAddress getter <strong>immediately</strong> after receiving a receipt so it should always get the right address as we also do it in sequence one after the other and thus it should always <strong>work</strong>!</p><p><strong>IMPROVEMENTS</strong></p><p>However, the first approach could still be improved by using an array of addresses for saving all the forwarder addresses in the contract but this would probably be too expensive with gas. However, we could always read all of the created forwarders and export all the unused ones! An even better would be to send the new forwarder address using events and catch in on the server, however according to previous experiences with<strong> EVENTS, which are horribly unpredictable,</strong> especially using <strong>INFURA</strong>, this would be recommended at a <strong>later</strong> <strong>stage</strong>, and all the created forwarders could change their parent addresses using the newly implemented function <strong>changeParent()</strong>.</p><h4>On data formatting</h4><p>It is crucial that inputting data is done using <strong>bytes32</strong> format. Oddly enough the format must be in <strong>HEX</strong> and <strong>not in bytes</strong> (as the name would suggest) :</p><p><a href="https://ethereum.stackexchange.com/questions/48092/solidity-error-when-encoding-arguments-to-call-a-function-with-bytes32-type-para">Solidity error when encoding arguments to call a function with Bytes32 Type Parameters</a></p><p>Therefore before inputting a string to a <strong>bytes32</strong> variable in solidity contract, a <strong>conversion</strong> like this must be done:</p><pre><strong>bytesVariable = Web3.toHex(string)</strong></pre><p>Why use <strong>bytes over strings</strong>:</p><p><a href="https://ethereum.stackexchange.com/questions/11556/use-string-type-or-bytes32">Use string type or bytes32?</a></p><h3>FINAL SOLUTION</h3><p>For the final solution, <strong>events</strong> were used as a means of transferring created forwarder address to the caller of this action. It was somehow a lucky strike as it was obvious that a receipt of a createForwarder() includes some logs that include event logs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*59sM6Z0AZoEsypBEw5tFyA.png" /><figcaption>an example of createForwarder() receipt in Remix that includes event logs in logs.</figcaption></figure><p><em>COMMENTS:</em></p><p><em>Here it must be said that in Remix if we only import WalletSimple contract as address without ABI the logs are empty when calling createForwarder(). This means that it is crucial to supply the </em><strong><em>correct</em></strong><em> </em><strong><em>ABI</em></strong><em> </em><strong><em>in</em></strong><em> </em><strong><em>web3.py</em></strong><em> so that we know events were called when calling createForwarder() and can thus get a return from it!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*bju8pVEFbY_0K6sNBCu7Sg.png" /><figcaption>Calling createForwarder() <strong>without</strong> returned logs as it was imported as an address. (probably no ABI supplied)</figcaption></figure><p>The event about generating forwarders was <strong>emitted</strong> in solidity in a contract like:</p><pre>function createForwarder() public payable returns (address) {<br> Forwarder f = new Forwarder();<br> <strong>emit ForwarderCreated(address(f));</strong><br> }</pre><p>Reading this using python:</p><pre><strong>txReceipt</strong> = web3.eth.waitForTransactionReceipt(transaction_address, timeout=3000)<br># get forwarder address from event logs!<br>data = <strong>txReceipt[&quot;logs&quot;][0][&quot;data&quot;]</strong><br>fAddr = <strong>&quot;0x&quot; + data[26:66]</strong><br>forwarderAddress = <strong>to_checksum_address(fAddr)</strong></pre><p>Additionally added an <strong>event</strong> for <strong>flushing</strong> <strong>tokens</strong> for future work so that we can follow flushing through events!</p><p>In the end, the whole contract was <strong>rewritten</strong> using the <strong>latest</strong> <strong>recommendations</strong> like in the solidity documentation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e257a621889d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/valus/forwarder-contract-for-ether-and-erc-20-tokens-e257a621889d">Forwarder contract for Ether and ERC-20 tokens</a> was originally published in <a href="https://medium.com/valus">VALUS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging Events on Ethereum]]></title>
            <link>https://medium.com/valus/logging-events-on-ethereum-755cd46bfe94?source=rss----bb07f462a264---4</link>
            <guid isPermaLink="false">https://medium.com/p/755cd46bfe94</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[events]]></category>
            <category><![CDATA[web3]]></category>
            <dc:creator><![CDATA[Primoz Kocevar]]></dc:creator>
            <pubDate>Wed, 21 Nov 2018 18:37:02 GMT</pubDate>
            <atom:updated>2019-06-06T21:57:08.955Z</atom:updated>
            <content:encoded><![CDATA[<h4>A quick insight into dealing with Ethereum events for logging purposes.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*eYLJm31X4RVxljLp7q1tyg.png" /></figure><h4>OVERVIEW</h4><p>When trying to look up some <strong>Ethereum</strong> <strong>Events</strong> using <strong>Web3.py</strong> for forwarding reasons I had some problems.</p><p>Why use <strong>events</strong> and how:</p><p><a href="https://media.consensys.net/technical-introduction-to-events-and-logs-in-ethereum-a074d65dd61e">Technical Introduction to Events and Logs in Ethereum</a></p><p>How to use Ethereum events with <strong>Python:</strong></p><p><a href="https://hackernoon.com/ethereum-smart-contracts-in-python-a-comprehensive-ish-guide-771b03990988">Ethereum Smart Contracts in Python: a comprehensive(ish) guide</a></p><p>For our use-case, this is kind of useless as it requires a TX receipt which we do not have in our case (or in any case when you <strong>don&#39;t save a TX receipt, </strong>which is in most cases).</p><h3><strong>USING INFURA AND WSS</strong></h3><p>As it turns out you can not use an Infura <strong>HTTP</strong> api if you would like to listen to events but you must use <strong>Websocket </strong>as a<strong> Web3 provider!!!</strong> A <strong>big help</strong> if you want to do it using <strong>INFURA</strong>:</p><p><a href="https://github.com/INFURA/infura/issues/73#issuecomment-365097830">Watching contract events with Infura · Issue #73 · INFURA/infura</a></p><p>Also Infura documentation for <strong>EVENTS</strong>, <strong>HELPFUL</strong>:</p><p><a href="https://infura.io/docs/wss/introduction">Infura - Scalable Blockchain Infrastructure</a></p><h3><strong>FILTERING EVENTS</strong></h3><p>Filtering events proved to be more difficult than expected as the provided documentation is quite clumsy and there are a few helpful must-know tricks.</p><p>The official documentation here was bit unhelpful as it suggested to use <em>fromBlock=’latest’</em> and using <em>filter.get_new_enteries() :</em></p><p><a href="https://web3py.readthedocs.io/en/latest/filters.html?highlight=filters">Filtering - Web3.py 4.6.0 documentation</a></p><p>This did not return any useful events as we should have used <strong>get_all_enteries(). </strong>As helpfully suggested here:</p><p><a href="https://ethereum.stackexchange.com/questions/49687/python-3-how-to-make-event-filter-via-createfilter-web3-py-v4-2-1?rq=1">Python 3 How to make Event Filter via createFilter web3.py v4.2.1</a></p><p><strong>On Event Filters and how to use them:</strong></p><p><a href="https://ethereum.stackexchange.com/questions/36009/web3-py-eventfilter-get-new-entries-always-empty?noredirect=1&amp;lq=1">Web3.py EventFilter.get_new_entries() always empty</a></p><p>In this present time 4.9.2018 it is unreliable to depend on the <strong>get_new_entries()</strong> function as filters have a problem with deleting:</p><p><a href="https://github.com/ethereum/web3.py/issues/923">&quot;filter not found&quot; in Web3.py 4.2.0 · Issue #923 · ethereum/web3.py</a></p><p><strong>Thus it is best to not rely on it and lookup if deposits are new by yourself locally! (looking up block numbers, or maybe id’s …)</strong></p><p><strong>PROBLEM</strong> with <strong>web3.py</strong> and <strong>websockets</strong> providers for INFURA is described here:</p><p><a href="https://github.com/ethereum/web3.py/issues/1009">websocket provider not working · Issue #1009 · ethereum/web3.py</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=755cd46bfe94" width="1" height="1" alt=""><hr><p><a href="https://medium.com/valus/logging-events-on-ethereum-755cd46bfe94">Logging Events on Ethereum</a> was originally published in <a href="https://medium.com/valus">VALUS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Invisible ReCaptcha Django]]></title>
            <link>https://medium.com/valus/invisible-recaptcha-django-ed06201161d5?source=rss----bb07f462a264---4</link>
            <guid isPermaLink="false">https://medium.com/p/ed06201161d5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Primoz Kocevar]]></dc:creator>
            <pubDate>Wed, 21 Nov 2018 18:15:21 GMT</pubDate>
            <atom:updated>2018-11-23T21:39:05.399Z</atom:updated>
            <content:encoded><![CDATA[<h4>Integrating a most user-friendly reCAPTCHA into your Django web platform.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*w1ORuN3k9TDQR07FBWPhfw.png" /></figure><p>There are some libraries for Django which you can use for this however, I prefer to do it by myself as it is more transparent and customizable (and in my case easier). To implement an invisible <strong>ReCaptcha </strong>by <strong>yourself </strong>using Django you start by using an official <strong>Google documentation</strong>:</p><p><a href="https://developers.google.com/recaptcha/docs/invisible">Invisible reCAPTCHA | Google for Developers</a></p><p>Here you have plenty of information on how to implement it on the <strong>front end</strong>. This means you only have to add a button with some crucial parameters like:</p><pre>&lt;button type=&quot;button&quot; <strong>data-sitekey</strong>=&quot;6LfKMG0UAAAAACdYaD7UE9dHIEsmmlmkL1SjE-AS&quot; <strong>data-callback</strong>=&quot;onClickResetPassValid&quot; class=&quot;<strong>g-recaptcha</strong> buttonColor anim&quot;&gt;Reset&lt;/button&gt;</pre><p>Then in the js function <em>onClickResetPassValid</em>() you can do the validation of the input data as this is called if the recaptcha is successful.</p><p>Next, we need to verify this request in the back-end before continuing using the usual code which uses a return field in the POST request named <strong>g-recaptcha-response</strong>:</p><pre>&#39;&#39;&#39; Begin reCAPTCHA validation &#39;&#39;&#39;<br>recaptcha_response = request.POST.get(&#39;g-recaptcha-response&#39;)<br>url = &#39;https://www.google.com/recaptcha/api/siteverify&#39;<br>values = {<br>    &#39;secret&#39;: settings.GOOGLE_RECAPTCHA_SECRET_KEY,<br>    &#39;response&#39;: recaptcha_response<br>}<br>data = urllib.parse.urlencode(values).encode()<br>req = urllib.request.Request(url, data=data)<br><br>response = urllib.request.urlopen(req)<br>result = json.loads(response.read().decode())<br>&#39;&#39;&#39; End reCAPTCHA validation &#39;&#39;&#39;<br>if result[&#39;success&#39;] == False:<br>    context = {&#39;recaptchaSuccess&#39;: False}<br>    return render(request, &#39;login/login.html&#39;, context)</pre><h4>PROBLEMS?</h4><p>Important to mention here is that if using validation in the front-end, there are some troubles and an approach mentioned in the first link (google documentation) should be used which is optimal. This approach would first validate the input data and after that use ReCaptcha validation.</p><p>However, we solved this problem differently as it suited our approach more. First, the reason for problems is that we need to <strong>reset </strong>the recaptcha after first calling the validation js function (e.g. onClickResetPassValid()) as the data-callback function can only be called once in the session if not reset. Therefore when we first call the validation function and possibly find a problem with data so that we do not submit the form, the button will not work for the second time (when we correct the data) as the recaptcha needs to be reset for the data-callback fuction to work again! This is done by using <strong><em>grecaptcha.reset() </em></strong>as mentioned here:</p><p><a href="https://groups.google.com/forum/#!topic/recaptcha/Y7xcoKhZ5OU">data-callback function not working in Invisible reCAPTCHA.</a></p><p>Calling <strong><em>grecaptcha.reset() </em></strong>should be implemented everytime the problem is detected in the js so that the ReCaptcha is reset and can work when the data is corrected. Example of this:</p><pre><strong>if </strong>(emailCond){<br>    $(&quot;#divCheckEmailLogin&quot;).slideUp(&quot;fast&quot;);<br>    $(&quot;#email&quot;).removeClass(&quot;inputWrongBorderRed&quot;);<br>}<br><strong>else </strong>{<br>    // reset recaptcha to try again!<br>    <strong>grecaptcha.reset();</strong><br>    $(&quot;#divCheckEmailLogin&quot;).slideDown(&quot;fast&quot;);<br>    $(&quot;#email&quot;).addClass(&quot;inputWrongBorderRed&quot;);<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed06201161d5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/valus/invisible-recaptcha-django-ed06201161d5">Invisible ReCaptcha Django</a> was originally published in <a href="https://medium.com/valus">VALUS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Ethereum Node]]></title>
            <link>https://medium.com/valus/aws-ethereum-node-c05266945b7e?source=rss----bb07f462a264---4</link>
            <guid isPermaLink="false">https://medium.com/p/c05266945b7e</guid>
            <category><![CDATA[distributed-ledgers]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Primoz Kocevar]]></dc:creator>
            <pubDate>Wed, 21 Nov 2018 18:12:49 GMT</pubDate>
            <atom:updated>2018-11-23T21:27:23.966Z</atom:updated>
            <content:encoded><![CDATA[<h4>My experiences and hacks dealing with setting up an Ethereum Blockchain on AWS instance.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*Alx4_-Pn0804yiuOUp7Tew.png" /></figure><h4>FIRST ATTEMPT</h4><p>One of my first attempts to achieve a full Ethereum node was using this code from AWS marketplace: <a href="https://aws.amazon.com/marketplace/pp/B073VZM29M">https://aws.amazon.com/marketplace/pp/B073VZM29M</a></p><p>However, after some time, I figured that this setup was set to create private nets and I wanted a full public node. I made the interface available to external communication by changing the setting in Ethereum.sh from <strong>-rpcaddr 127.0.0.1</strong> to <strong>0.0.0.0 </strong>and also changing the security settings in AWS console to let in ingoing traffic on port 8545. However, as this was not very useful to me at the moment I accepted another approach to have as efficient as possible public node available.</p><h4>PARITY ATTEMPT</h4><p>As a first real attempt at manually setting up an Ethereum node on an AWS, I set up a micro EC2 instance. Then I installed Parity node on that instance as recommended here:</p><p><a href="https://medium.com/coinmonks/run-an-ethereum-node-on-aws-for-free-afca27f253ed">Run an Ethereum Node on AWS for Free</a></p><p>The instance also had quite a small amount of RAM and storage (30 GB) and probably because of these reasons the synchronization with the Ethereum main net was failing. After many attempts, the sync node was stuck at a random number and after a weekend of retries I gave up on the idea and looked for another approach.</p><h4>GETH FINAL SOLUTION</h4><p>The next logical step was trying a <strong>Geth</strong> node as is a standard for the Ethereum network. This was not a recommended way according to some developers that had better experiences with <strong>Parity </strong>as it is supposedly more <strong>storage efficient </strong>and <strong>faster</strong>. This time I did not want to make the same mistake and reserved a much stronger EC2 instance in AWS. The instance I choose was a <strong>large</strong> type and it has<strong> 200 GB</strong> of SSD storage. Here it must be considered that the same size of node could perform even better if Parity was used. This was done as recommended here:</p><p><a href="https://ethereum.stackexchange.com/questions/37120/best-possible-way-to-launch-the-ethereum-mainnet-node-on-aws">Best possible way to launch the ethereum mainnet node on AWS</a></p><p>Installation of <strong>Geth</strong> on the <strong>AWS</strong> <strong>EC2</strong> <strong>Ubuntu</strong> image instance:</p><p><a href="https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu">ethereum/go-ethereum</a></p><p>After some syncing attempts, It is important to go with the option when <strong>syncing to geth </strong>like:</p><pre>geth --syncmode=fast --cache=1024 --rpc --rpcaddr 0.0.0.0 --rpcport 3000</pre><p>This command is very important to get correct!</p><ul><li><em>SYNCMODE</em>: you can also use light or full options, but mostly fast is optimal</li><li><em>CACHE</em>: 1024 for faster synchronization! (if lots of RAM also 2048 is possible)</li><li><em>RPC </em>option must be enabled to have an RPC port open</li><li><em>RPCADDR </em>must be set to 0.0.0.0 so that it is accessible from outside!(or an IP on which the node lives)</li><li><em>RPCPORT </em>is usually 8545 as this is a default for geth nodes used for RPC calls. I use port 3000 for security from bots that try the 8545 port systematically!</li></ul><p>The syncing of the Ethereum network can be stuck at the end like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*TfWc5v06Vm1eUAQOtAgbFA.png" /></figure><p>However, this is explained:</p><p><a href="https://github.com/ethereum/go-ethereum/issues/16796">Geth node sync always behind · Issue #16796 · ethereum/go-ethereum</a></p><p>Some other options to run geth described here:</p><p><a href="https://github.com/ethereum/go-ethereum/issues/14536">Unable to attach to the local running geth node · Issue #14536 · ethereum/go-ethereum</a></p><p><strong>Testing the node:</strong></p><ul><li><a href="https://ethereum.stackexchange.com/questions/46841/what-is-context-deadline-exceeded">what is context deadline exceeded?</a></li><li><a href="https://ethereum.stackexchange.com/questions/809/which-tcp-and-udp-ports-are-required-to-run-an-ethereum-client">Which TCP and UDP ports are required to run an Ethereum client?</a></li></ul><p><strong>Attaching to Ropsten node:</strong></p><p>Attaching to ropsten via IPC connection is not as simple as main net (as it uses a different folder) so use the next instructions or just connect to an HTTP <strong>RPC</strong> which is the same for ropsten as is for mainnet:</p><p><a href="https://ethereum.stackexchange.com/questions/11248/how-to-call-geth-attach-on-testnet-better-than-writing-full-path">How to call &quot;geth attach&quot; on --testnet better than writing full path?</a></p><p><strong>Useful stuff:</strong></p><p><a href="https://github.com/ethereum/go-ethereum/issues/16353">connection refused to Geth websocket / RPC ports · Issue #16353 · ethereum/go-ethereum</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c05266945b7e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/valus/aws-ethereum-node-c05266945b7e">AWS Ethereum Node</a> was originally published in <a href="https://medium.com/valus">VALUS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Django application to AWS using Elastic Beanstalk]]></title>
            <link>https://medium.com/valus/deploying-a-django-aplication-to-aws-using-elastic-benstalk-9c39a06c7b28?source=rss----bb07f462a264---4</link>
            <guid isPermaLink="false">https://medium.com/p/9c39a06c7b28</guid>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[elastic-beanstalk]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Primoz Kocevar]]></dc:creator>
            <pubDate>Wed, 21 Nov 2018 18:07:57 GMT</pubDate>
            <atom:updated>2018-11-23T21:43:08.072Z</atom:updated>
            <content:encoded><![CDATA[<h4>Hacks and problems when deploying a Django application to AWS.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*3BGIfZTVdBYAlIOPbjaIsQ.png" /></figure><p>Disclaimer: <em>This post is not meant as a tutorial but a dense description of possible functionalities and problems you can encounter and how to solve them.</em></p><h4>Elastic Beanstalk or EC2?</h4><p>First, read a discussion between Elastic Beanstalk and EC2 here:</p><p><a href="https://stackoverflow.com/questions/25956193/difference-between-amazon-ec2-and-aws-elastic-beanstalk">Difference between Amazon ec2 and AWS Elastic Beanstalk</a></p><p>This will help you decide if you need one or the other. Deploying on <strong>Elastic Beanstalk(EB) </strong>is much <strong>faster </strong>and <strong>easier </strong>once you get used to it, but it can provide <strong>less control </strong>(or differently control is harder to obtain, digging into different settings can sometimes be tedious and has to be done using .config and .yaml files in the respective .elasticbeanstalk and .ebextenstions folders in the Django project<em>.</em>). Thus if you have a need for a very <strong>custom</strong> setup of your project and some special libraries outside of Django, then maybe EC2 is a better choice.</p><h4>BASIC SETUP</h4><p>Moving on, a starting point for deploying a Django application with Beanstalk is best described in <strong>official</strong> <strong>AWS</strong> documentation:</p><p><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html">Deploying a Django application to Elastic Beanstalk</a></p><p>This describes how to set up a basic project with a “local” SQLite database.</p><h4>ADDING A SEPARATE DB</h4><p>However, in most cases, a <strong>separate DB instance </strong>is needed as in the case of using SQLite you will <strong>erase</strong> all changes in the database when you upload a new version of your application to EB. This next un-official guide describes the whole process of setting up a Django project on EB, however, we will only focus on the parts describing how to add a database and the parts regarding setting up a <em>superuser</em> and <em>collectstatic</em>:</p><p><a href="https://realpython.com/deploying-a-django-app-to-aws-elastic-beanstalk/#configuring-a-database">Deploying a Django App to AWS Elastic Beanstalk - Real Python</a></p><p>and an <strong>official</strong> documentation<em>:</em></p><p><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.db.html">Adding a Database to Your Elastic Beanstalk Environment - AWS Elastic Beanstalk</a></p><p>If you have a separate DB instance deployed on AWS and want to access it from <strong>outside </strong>(other than with the admin panel using Django) you will first need to add an <strong>inbound</strong> <strong>security</strong> <strong>rule</strong> like here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*f63Znrac_aGQQkPqdJ26nQ.png" /></figure><p>The whole process of doing this for a Postgres DB is described here:</p><p><a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToPostgreSQLInstance.html">Connecting to a DB instance running the PostgreSQL database engine</a></p><p>However, this process can produce some <strong>unexpected problems </strong>if you change the database password and username in the <strong>instances section </strong>in AWS and this than is somehow not in sync with the <strong>settings in Elastic Beanstalk section </strong>and thus brings problems with authorization or an ID of a DB instance cannot be found because of this. But this is more a problem of AWS and we can do nothing about it. Best is just to leave the settings of a DB as they were when initialized with the EB otherwise we must provide the changed authorization info <strong>directly</strong> in a <strong>Django</strong> <strong>settings</strong> file which is <strong>insecure</strong>.</p><p>All of this things are operated from the <strong>config files</strong> in the Django project as this is where you specify what bash commands to run and when on the EC2 instance that is running beneath EB. You can also change the EC2 environment settings manually by accessing the EC2 instance using <strong>SSH</strong> however, this is only a <strong>temporary</strong> solution until the next time you deploy to this EB instance as then all of the settings are reset and only the settings specified in the .config files are respected. More about this:</p><p><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html">Advanced environment customization with configuration files (.ebextensions)</a></p><h4>ADDING A DOMAIN</h4><p>Adding a custom domain on top of EB environment is done by <strong>Route 53</strong> as this is the tool for connecting domains and instances inside and outside AWS. The process for EB is described here:</p><p><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customdomains.html">Your Elastic Beanstalk Environment&#39;s Domain Name - AWS Elastic Beanstalk</a></p><p>When setting up a domain you can decide to provide a <strong>CNAME</strong> string to connect with a domain or a <strong>static</strong> <strong>IP</strong> and the choice is up to you, I prefer providing a <strong>CNAME </strong>as it is constant as opposed to an <strong>IP address</strong> that can possibly change.</p><p>We should also mention that setting up domains inside AWS with Route 53 is very <strong>simple</strong> and it is simple to change the platform running behind a certain domain with just a few clicks inside the AWS console using <strong>elastic IPs</strong>. The only delay that can happen is when changing <strong>DNS</strong> servers which can take<strong> a few hours</strong> to propagate.</p><h4>SETTING UP HTTPS</h4><p>Setting up an <strong>HTTPS</strong> certificate on <strong>EB</strong> is pretty simple and is generally described here:</p><p><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/configuring-https.html">Configuring HTTPS for Your Elastic Beanstalk Environment</a></p><p>However, firstly you must obtain or import an SSL certificate for your domain. Obtaining an <strong>SSL certificate</strong> with Amazon is described here:</p><p><a href="https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html">Requesting a public certificate</a></p><p>When you have an SSL certificate in your AWS console you must only connect it to your Load Balancer by adding a new configuration file to your Django project or doing it through AWS Console:</p><p><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/configuring-https-elb.html">Configuring Your Elastic Beanstalk Environment&#39;s Load Balancer to Terminate HTTPS</a></p><h4>REDIRECTING TO SSL</h4><ol><li><strong>Option: (<em>with Django</em>)</strong></li></ol><p>Django production settings set correctly will <strong>redirect</strong> to HTTPS <strong>automatically</strong>:</p><p><a href="https://docs.djangoproject.com/en/2.0/ref/middleware/#http-strict-transport-security">Middleware | Django documentation | Django</a></p><p>example of <strong>production</strong> settings in Django:</p><pre>CORS_REPLACE_HTTPS_REFERER      = True<br>HOST_SCHEME                     = &quot;https://&quot;<br>SECURE_PROXY_SSL_HEADER         = (&#39;HTTP_X_FORWARDED_PROTO&#39;, &#39;https&#39;)<br>SECURE_SSL_REDIRECT             = True<br>SESSION_COOKIE_SECURE           = True<br>CSRF_COOKIE_SECURE              = True<br>SECURE_HSTS_PRELOAD             = True<br>SECURE_HSTS_INCLUDE_SUBDOMAINS  = True<br>SECURE_HSTS_SECONDS             = 1000000<br>SECURE_FRAME_DENY               = True<br><br>SECURE_CONTENT_TYPE_NOSNIFF     = True<br>SECURE_BROWSER_XSS_FILTER       = True<br>X_FRAME_OPTIONS                 = &#39;DENY&#39;</pre><p>2. <strong>Option (using .conf files)</strong></p><p>Additionally to be safe, when setting up HTTPS we would like to <strong>redirect</strong> all traffic to the HTTPS port even if it comes to the HTTP port and this is done by adding this lines to your <strong>configuration</strong> file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4abaf954b3e038d0d976f7cefc31cd25/href">https://medium.com/media/4abaf954b3e038d0d976f7cefc31cd25/href</a></iframe><p><em>Note that we must not turn off the HTTP (80) port completely in the AWS console as then the redirection will not work and only HTTPS (443) port will work.</em></p><h4>DEPLOYING FROM A NEW COMPUTER</h4><p>Beanstalk environment click <strong>Actions</strong> and <strong>Load</strong> <strong>Configurations</strong> and then application versions to see a history of all uploaded versions! Do this when <strong>deploying from new computers! </strong>Then paste the content of a zip file over an svn (or some kind of version control) folder of the same project so we thus enable versioning and take the content of a zip primarily when replacing. The only thing needed to start a successful eb init now is a config.yaml file from .elasticbeanstalk folder that needs to be copied from the other computer. Then try to start an eb init command in this folder so that you <strong>don&#39;t</strong> start a new project but just continue with<strong> an existing one. </strong>Check this by running eb status after it to confirm it is connected to the right beanstalk environment.</p><h4><strong>FRESH MIGRATIONS EXTERNAL RDS (clean DB)</strong></h4><p>For my use case, I found a very simple solution by simply rebuilding an EB environment through the console. This automatically creates a new RDS database instance with the same settings but it does not apply any snapshots and thus the new database is empty. This was very useful when applying new migrations with Django. Hope this is helpful, more information here:</p><p><a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-management-rebuild.html">Rebuilding AWS Elastic Beanstalk Environments - AWS Elastic Beanstalk</a></p><h4>ADDING A DEV ENVIRONMENT TO THE EB APPLICATION</h4><p>When trying to add a second working environment to a specific AWS EB application (e.g. PiplShare) this can be done in multiple ways. The most simple is to combine the creation of the environment and setting up the initial settings with the AWS console through <strong>GUI</strong>. It is helpful to set the new environment to be pre-configured for Python and also deploy an old application version of our production environment to the new environment just to test it.</p><p>The most <strong>important</strong> step is transferring the settings from the already working environment to the new one. This is done by copying the <strong>*.yaml</strong> file in the <strong>.elasticbeanstalk</strong> folder in the root of the project. Very important is to <strong>change the specified environment in the *.yaml </strong>file<strong> </strong>to the newly created one so that when we try to deploy we do not overwrite the production server and by this, we <strong>differentiate</strong> between two environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*ZJJxnSX6iYE_V2Ax2IYFPA.png" /><figcaption>config.yaml examples for two environments of the same application.</figcaption></figure><p><em>Two remarks should be made here. We should add a </em><strong><em>new</em></strong><em> environment </em><strong><em>URL</em></strong><em> to the </em><strong><em>ALLOWED_HOSTS</em></strong><em> in Django settings. Setting up new </em><strong><em>requirements.txt </em></strong><em>file is also necessary for the deploy to work or in the opposite case, we can get a </em><strong><em>Django import error</em></strong><em>. This file can be the same as on the production env or different if we use different libraries than the following command must be run to update the requirements according to a local python virtual environment:</em></p><pre>pip freeze &gt; requirements.txt</pre><h4><strong>COMMENTS</strong></h4><p>A developer must be aware of the fact that every time he/she <strong>deploys</strong> a new version of the project it will completely <strong>erase</strong> the whole environment and deploy only the new folder from which we are deploying. Therefore it will also only install libraries mentioned in the requirements.txt and all additional bash commands must be specified in the <strong>*.config</strong> file.</p><p>For building production APIs check out different load balancing mechanisms as they may be more appropriate:</p><p><a href="https://aws.amazon.com/elasticloadbalancing/">Load Balancer - Elastic Load Balancing (ELB) - AWS</a></p><p>For different problems and issues during the deployment please contact me or refer to the text <strong>AWS troubles.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c39a06c7b28" width="1" height="1" alt=""><hr><p><a href="https://medium.com/valus/deploying-a-django-aplication-to-aws-using-elastic-benstalk-9c39a06c7b28">Deploying a Django application to AWS using Elastic Beanstalk</a> was originally published in <a href="https://medium.com/valus">VALUS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>