GithubHelp home page GithubHelp logo

humanode-evm-workshop-2022's Introduction

Intro

This workshop is primarily for developers who understand the basics of evm (Ethereum virtual machine) smart contracts. It covers environment setup, and basic smart contract development and deployment to the Humanode network using Truffle or Remix.

Requirements

  • Web browser (Firefox or Chrome)
  • Linux or Mac
  • Familiarity with the terminal
  • npm
  • MetaMask
  • wget or curl

Setup

First we need to setup our dev node. This is useful for testing changes in a sandbox environment, where we don't have to worry about destructive action.

To begin, let's create a directory for our node:

mkdir humanode-peer
cd humanode-peer

Now to download the humanode-peer binary.

The URL of the binary is different depending on OS and architecture. Use the following manifest file to determine the correct location for your system: https://chainspec.testnet3.stages.humanode.io/latest/manifest.json

The URL for your system is calculated using the base url + suburl: https://chainspec.testnet3.stages.humanode.io{subUrl} where {subUrl} is the value found in the manifest file above.

Download binary (Linux x86_64):

curl -LSs https://chainspec.testnet3.stages.humanode.io/latest/binaries/Linux-x86_64/humanode-peer -o humanode-peer

Download binary (Darwin x86_64):

curl -LSs https://chainspec.testnet3.stages.humanode.io/latest/binaries/Darwin-x86_64/humanode-peer -o humanode-peer

Now we have to change the file permissions to make it executable:

chmod +x humanode-peer

Finally run the executable:

./humanode-peer --tmp --dev

Using Truffle

Truffle is a suite of tools for smart contract development.

Humanode provides a truffle box that can be used to develop and deploy smart contracts to the Humanode network. It can be used as a template, or unboxed using the truffle unbox command. To use as a template, click the "use template" button in github and follow the instructions in the readme.

Instructions for using truffle unbox are below.

First we create a new directory for our truffle project:

mkdir my-contracts
cd my-contracts

Make sure you have truffle installed:

npm install -g truffle

Next unbox the Humanode truffle box (this can take a while):

truffle unbox humanode-network/humanode-truffle-box

Write your contracts (example contracts/MyToken.sol shown below).

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

// Import OpenZeppelin Contract
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

// This ERC-20 contract mints the specified amount of tokens to the contract creator.
contract MyToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("MyToken", "MYTOK") {
        _mint(msg.sender, initialSupply);
    }
}

Test contracts on the Humanode network:

truffle test --network dev

Deploy contracts to the Humanode network:

truffle deploy --network dev

Using Remix

Remix is a web IDE for quick and easy smart contract development and deployment. To use Remix, we first need to connect our local node to MetaMask.

MetaMask is a crypto wallet and gateway for blockchain apps. Download and install the MetaMask extension for your browser: https://metamask.io/

Once installed, create a new wallet.

Add our network to MetaMask through Settings -> Networks -> Add a network, and enter the following details:

Network name: Humanode DEV

RPC URL: http://127.0.0.1:9933

Chain ID: 5234

Currency Symbol: HMND

To deploy and run contracts you need an account with gas. A pre-funded dev account is provided. Import the following address into MetaMask: 0x99b3c12287537e38c90a9219d4cb074a89a16e9cdb20bf85728ebd97c343e342.

Go to https://remix.ethereum.org/

For the popup, select the development account you just imported.

Compile contract, and deploy with "Injected Web3".

Extra

  • Polkadotjs: use the Polkadot explorer to debug chain events and transactions: https://polkadot.js.org/apps/#/explorer

  • Desktop app: we've downloaded the binary directly, but everything you see here is also possible using the desktop app. Please review the Humanode docs for more information: https://desktop-app-docs.humanode.io/

  • Open source: we plan on taking Humanode open-source, however this will be after mainnet launch. We don't want people to use it before it's ready.

  • Pallet EVM: Humanode is built using Substrate, which is a framework for making blockchains. It lets you compose your blockchain with building blocks called "pallets". One of the pallets we use is called pallet_evm, which implements the Ethereum virutal machine. This means any smart contract that runs on Ethereum can also run on Humanode.

humanode-evm-workshop-2022's People

Contributors

intendednull avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.