avatarCaleb

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

6308

Abstract

tract!</p><p id="0f8d">Create a new file <code>SimpleStorage.sol</code> in the <code>/contracts</code> directory. In this contract, you're constructing a simple storage unit:</p><div id="2b19"><pre>pragma solidity >=<span class="hljs-number">0.4</span><span class="hljs-number">.22</span> <<span class="hljs-number">0.9</span><span class="hljs-number">.0</span>;

contract SimpleStorage { <span class="hljs-built_in">uint</span> storedData;

<span class="hljs-function">function <span class="hljs-title">set</span>(<span class="hljs-params"><span class="hljs-built_in">uint</span> x</span>) <span class="hljs-keyword">public</span></span> { storedData = x; }

<span class="hljs-function">function <span class="hljs-title">get</span>() <span class="hljs-keyword">public</span> view <span class="hljs-title">returns</span> (<span class="hljs-params"><span class="hljs-built_in">uint</span></span>)</span> { <span class="hljs-keyword">return</span> storedData; } }</pre></div><p id="ccc4">Compile the contract using:</p><div id="a2ce"><pre>truffle <span class="hljs-built_in">compile</span></pre></div><p id="ec83">And voila! Your first Ethereum smart contract is ready!</p><h1 id="8823">Step 6: Deploying Your Smart Contract — Migrating Your Contract</h1><p id="087f">Create a new file <code>2_deploy_contracts.js</code> in the <code>/migrations</code> directory:</p><div id="9c53"><pre><span class="hljs-keyword">const</span> <span class="hljs-title class_">SimpleStorage</span> = artifacts.<span class="hljs-built_in">require</span>(<span class="hljs-string">"SimpleStorage"</span>);

<span class="hljs-variable language_">module</span>.<span class="hljs-property">exports</span> = <span class="hljs-keyword">function</span>(<span class="hljs-params">deployer</span>) { deployer.<span class="hljs-title function_">deploy</span>(<span class="hljs-title class_">SimpleStorage</span>); };</pre></div><p id="0529">Run the migration with Ganache as your network using:</p><div id="e312"><pre>truffle migrate <span class="hljs-attr">--network</span> development</pre></div><p id="c3f6">Now, your smart contract lives in your Ethereum sandbox!</p><div id="614f"><pre>truffle migrate --network development

Compiling your contracts...

<span class="hljs-meta prompt_">> </span><span class="language-bash">Everything is up to <span class="hljs-built_in">date</span>, there is nothing to compile.</span>

Starting migrations...

<span class="hljs-meta prompt_">> </span><span class="language-bash">Network name: <span class="hljs-string">'development'</span></span> <span class="hljs-meta prompt_">> </span><span class="language-bash">Network <span class="hljs-built_in">id</span>: 5777</span> <span class="hljs-meta prompt_">> </span><span class="language-bash">Block gas <span class="hljs-built_in">limit</span>: 6721975 (0x6691b7)</span>

2_deploy_contracts.js

Deploying 'SimpleStorage'

<span class="hljs-meta prompt_"> > </span><span class="language-bash">transaction <span class="hljs-built_in">hash</span>: 0xe2881646c2731d4b26a11a829e0dabd1461c30ddcef19e8dfee593c8d1eef745</span> <span class="hljs-meta prompt_"> > </span><span class="language-bash">Blocks: 0 Seconds: 0</span> <span class="hljs-meta prompt_"> > </span><span class="language-bash">contract address: 0x8148cE37C3A1E8E8E689724d41900a8132AC1C18</span> <span class="hljs-meta prompt_"> > </span><span class="language-bash">block number: 1</span> <span class="hljs-meta prompt_"> > </span><span class="language-bash">block timestamp: 1687467217</span> <span class="hljs-meta prompt_"> > </span><span class="language-bash">account: 0xBd99cDAbA45630391b60b32ff8Cd4b9F51B97EbB</span> <span class="hljs-meta prompt_"> > </span><span class="language-bash">balance: 99.999575921125</span> <span class="hljs-meta prompt_"> > </span><span class="language-bash">gas used: 125653 (0x1ead5)</span> <span class="hljs-meta prompt_"> > </span><span class="language-bash">gas price: 3.375 gwei</span> <span class="hljs-meta prompt_"> > </span><span class="language-bash">value sent: 0 ETH</span> <span class="hljs-meta prompt_"> > </span><span class="language-bash">total cost: 0.000424078875 ETH</span>

<span class="hljs-meta prompt_"> > </span><span class="language-bash">Saving artifacts</span>

<span class="hljs-meta prompt_"> > </span><span class="language-bash">Total cost: 0.000424078875 ETH</span>

Summary

<span class="hljs-meta prompt_">> </span><span class="language-bash">Total deployments: 1</span> <span class="hljs-meta prompt_">> </span><span class="language-bash">Final cost: 0.000424078875 ETH</span></pre></div><figure id="16a6"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*K-vKZOtxyh0iChtZhKfLbQ.png"><figcaption></figcaption></figure><h1 id="ea7b">Conclusion</h1><p id="443f">With this guide, you’ve taken more than a few significant strides into the world of Ethereum development. The cityscape of Ethereum now lies open to your innovation and creativity, welcoming the unique structures you’ll create, and the new paths you’ll carve out in the bustling streets of this blockchain metropolis.</p><p id="19d4">Remember, there’s always more to learn and discover, but you’re well on your way. After all, as an Ethereum developer, you’re not just a tourist, but an active participant, shaping Ethereum city’s ever-evolving skyline with your codes and keystrokes. Welcome to the exciting journey of Ethereum development. Enjoy the ride!</p><div id="766a" class="link-block"> <a href="https://ethereum.org/en/"> <div> <div> <h2>Home | ethereum.org</h2> <div><h3>Ethereum is a global, decentralized platform for money and new kinds of applications. On Ethereum, you can write code…</h3></div> <div><p>ethereum.org</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*v

Options

mrdZCaGKZPJjI9I)"></div> </div> </div> </a> </div><div id="3075" class="link-block"> <a href="https://github.com/ethereum"> <div> <div> <h2>ethereum</h2> <div><h3>ethereum has 288 repositories available. Follow their code on GitHub.</h3></div> <div><p>github.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*JlIEguWbb8HwgePT)"></div> </div> </div> </a> </div><div id="e0db" class="link-block"> <a href="https://trufflesuite.com/docs/ganache/"> <div> <div> <h2>Ganache | Overview - Truffle Suite</h2> <div><h3>Ganache is a personal blockchain for rapid Ethereum and Filecoin distributed application development. You can use…</h3></div> <div><p>trufflesuite.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*-bkSjKqNicoAzQd0)"></div> </div> </div> </a> </div><div id="dd7e" class="link-block"> <a href="https://nodejs.org/en/docs"> <div> <div> <h2>Documentation | Node.js</h2> <div><h3>Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.</h3></div> <div><p>nodejs.org</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*bdNgKFJZQMZKekip)"></div> </div> </div> </a> </div><div id="695b" class="link-block"> <a href="https://trufflesuite.com/docs/"> <div> <div> <h2>Documentation</h2> <div><h3>Guides to using Truffle, Ganache and Drizzle including quickstart guides, testing instructions, platform commands…</h3></div> <div><p>trufflesuite.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*575BnvqpdST05wiZ)"></div> </div> </div> </a> </div><div id="bbf6" class="link-block"> <a href="https://docs.soliditylang.org/en/v0.8.20/"> <div> <div> <h2>Solidity - Solidity 0.8.20 documentation</h2> <div><h3>When deploying contracts, you should use the latest released version of Solidity. Apart from exceptional cases, only…</h3></div> <div><p>docs.soliditylang.org</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/)"></div> </div> </div> </a> </div><div id="9c62" class="link-block"> <a href="https://trufflesuite.com/docs/truffle/how-to/contracts/interact-with-your-contracts/"> <div> <div> <h2>Interact with your contracts - Truffle Suite</h2> <div><h3>If you were writing raw requests to the Ethereum network yourself in order to interact with your contracts, you'd soon…</h3></div> <div><p>trufflesuite.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*VrfBOHdPno7dXnpl)"></div> </div> </div> </a> </div><div id="30d1" class="link-block"> <a href="https://medium.com/@calebpr/subscribe"> <div> <div> <h2>Get an email whenever Caleb publishes.</h2> <div><h3>Get an email whenever Caleb publishes. By signing up, you will create a Medium account if you don’t already have one…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*pPSGj3ORvqLvuBYg)"></div> </div> </div> </a> </div><p id="91bd"><i>Enjoyed the read? For more on Web Development, JavaScript, Next.js, Cybersecurity, and Blockchain, check out my other articles here:</i></p><div id="7e3a" class="link-block"> <a href="https://readmedium.com/a-roadmap-to-my-medium-writings-fd04e14cffd7"> <div> <div> <h2>A Roadmap to My Medium Writings</h2> <div><h3>undefined</h3></div> <div><p>undefined</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*FO4S90VIpPA05s9cP-gFPQ.png)"></div> </div> </div> </a> </div><p id="8496"><i>If you have questions or feedback, don’t hesitate to reach out at [email protected] or in the comments section.</i></p><p id="c73a"><i>[Disclosure: Every article I pen is a fusion of my ideas and the supportive capabilities of artificial intelligence. While AI assists in refining and elaborating, the core thoughts and concepts stem from my perspective and knowledge. <a href="https://readmedium.com/how-does-ai-help-me-write-my-articles-5df265d16527">To know more about my creative process, read this article.</a>]</i></p><div id="a005" class="link-block"> <a href="https://readmedium.com/how-does-ai-help-me-write-my-articles-5df265d16527"> <div> <div> <h2>How Does AI Help Me Write My Articles?</h2> <div><h3>The Medium landscape has seen a transformation, with an increasing number of articles appearing to have the distinct…</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*sURudlO3SS5ntthELFumcg.jpeg)"></div> </div> </div> </a> </div></article></body>

Ethereum Development Environment Setup: A Step-By-Step Tutoriel

Welcome, adventurous coder, to the exciting world of Ethereum development!

In this guide, we’re going to embark on a journey to set up your own Ethereum development environment, unraveling the complexities.

Step 1: Choosing Your Tools

First and foremost, you need a set of tools.

Node.js and npm

To install Node.js and npm, visit the official Node.js download page, download and install the recommended version for your OS.

Truffle

Next up is Truffle, your personal Ethereum workbench. It simplifies contract deployment, testing, and overall project management. Truffle is like a seasoned local guide who knows every nook and cranny of an Ethereum city, making your development journey smoother. Install Truffle globally using npm:

npm install -g truffle

Step 2: Downloading and Opening Ganache — Your Personal Ethereum Sandbox

Ganache is your personal sandbox. It provides a safe environment to experiment and test your smart contracts without any real-world consequences.

However, before you can play in this sandbox, you need to know how to access it.

This section will guide you on how to download and open Ganache.

Downloading Ganache

The journey to our sandbox begins at the official Ganache website. There, you’ll find the “Download” button. Click it and select the version suitable for your operating system.

After downloading the installer, it’s time to install Ganache on your machine.

Run the installer and follow the on-screen instructions. In no time, you’ll have Ganache installed and ready to go.

Opening Ganache

With Ganache installed, you can now open it just like any other software on your machine:

  • On Windows, navigate to your Start menu. Click on the Start button, scroll through your list of installed applications until you find Ganache, and click to open it.
  • On macOS, delve into your Applications folder, locate Ganache, and double-click to open it.
  • On Linux, the process might vary depending on your specific distribution and how you installed Ganache. Generally, you can find it in your applications menu. If you installed it via a package manager, you might be able to launch it using a command like ganache.

Upon opening Ganache, you’ll encounter a screen where you can create a new workspace or open an existing one.

For beginners, it’s recommended to click on “Quickstart” to create a new workspace with default settings.

This workspace fires up a local Ethereum blockchain, allowing you to peek into its details including accounts, blocks, transactions, and contracts.

Remember, Ganache should be kept running while you’re developing your Ethereum applications. It acts as your local Ethereum node, and your applications will interact with it as if it were the actual Ethereum network.

Step 3: Setting up Base Camp — The Project Directory

Like any successful journey, organization is key. Our ‘base camp’ is the project directory.

First, create a new directory for your project. You can use the terminal or command prompt:

mkdir my-eth-project
cd my-eth-project

To set up the Truffle project, initiate it with:

truffle init

This command conjures a well-structured project directory for you. Think of it as a pre-built base camp, complete with essentials and a map of the area.

Then, you need to specify a network_id in your Truffle configuration for the 'development' network.

  1. Open the truffle-config.js or truffle.js file in the root of your project. This is where your project's configuration is located.
  2. Locate the networks property. It's an object containing the configurations for different networks.
  3. In the development object (which is one of the networks), add a network_id property and assign it an arbitrary number, like so:
module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545, // or the port that you have configured for Ganache
      network_id: 5777
    }
  }
  // rest of your config...
};

The configuration must be the same in Ganache Settings > Server:

Step 4: Interacting with Ethereum— The MetaMask Wallet

You’ll need a wallet to interact with contracts and transactions. MetaMask serves as your digital wallet and passport, giving you an identity on the Ethereum network. To install MetaMask, go to the official MetaMask website and add it as an extension to your browser.

Step 5: Ready to Build — Writing Your First Contract

With base camp set and tools in hand, it’s time to create your first smart contract!

Create a new file SimpleStorage.sol in the /contracts directory. In this contract, you're constructing a simple storage unit:

pragma solidity >=0.4.22 <0.9.0;

contract SimpleStorage {
  uint storedData;

  function set(uint x) public {
    storedData = x;
  }

  function get() public view returns (uint) {
    return storedData;
  }
}

Compile the contract using:

truffle compile

And voila! Your first Ethereum smart contract is ready!

Step 6: Deploying Your Smart Contract — Migrating Your Contract

Create a new file 2_deploy_contracts.js in the /migrations directory:

const SimpleStorage = artifacts.require("SimpleStorage");

module.exports = function(deployer) {
  deployer.deploy(SimpleStorage);
};

Run the migration with Ganache as your network using:

truffle migrate --network development

Now, your smart contract lives in your Ethereum sandbox!

truffle migrate --network development

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.


Starting migrations...
======================
> Network name:    'development'
> Network id:      5777
> Block gas limit: 6721975 (0x6691b7)


2_deploy_contracts.js
=====================

   Deploying 'SimpleStorage'
   -------------------------
   > transaction hash:    0xe2881646c2731d4b26a11a829e0dabd1461c30ddcef19e8dfee593c8d1eef745
   > Blocks: 0            Seconds: 0
   > contract address:    0x8148cE37C3A1E8E8E689724d41900a8132AC1C18
   > block number:        1
   > block timestamp:     1687467217
   > account:             0xBd99cDAbA45630391b60b32ff8Cd4b9F51B97EbB
   > balance:             99.999575921125
   > gas used:            125653 (0x1ead5)
   > gas price:           3.375 gwei
   > value sent:          0 ETH
   > total cost:          0.000424078875 ETH

   > Saving artifacts
   -------------------------------------
   > Total cost:      0.000424078875 ETH

Summary
=======
> Total deployments:   1
> Final cost:          0.000424078875 ETH

Conclusion

With this guide, you’ve taken more than a few significant strides into the world of Ethereum development. The cityscape of Ethereum now lies open to your innovation and creativity, welcoming the unique structures you’ll create, and the new paths you’ll carve out in the bustling streets of this blockchain metropolis.

Remember, there’s always more to learn and discover, but you’re well on your way. After all, as an Ethereum developer, you’re not just a tourist, but an active participant, shaping Ethereum city’s ever-evolving skyline with your codes and keystrokes. Welcome to the exciting journey of Ethereum development. Enjoy the ride!

Enjoyed the read? For more on Web Development, JavaScript, Next.js, Cybersecurity, and Blockchain, check out my other articles here:

If you have questions or feedback, don’t hesitate to reach out at [email protected] or in the comments section.

[Disclosure: Every article I pen is a fusion of my ideas and the supportive capabilities of artificial intelligence. While AI assists in refining and elaborating, the core thoughts and concepts stem from my perspective and knowledge. To know more about my creative process, read this article.]

Ethereum
Blockchain
Smart Contracts
Cryptocurrency
Solidity
Recommended from ReadMedium