Giter Site home page Giter Site logo

hello-smart-contract-alchemy-tutorial's Introduction

Hello World Alchemy

Following the official tutorial in the Alchemy GitHub. This tutorial is not available on the official docs website but only on GitHub.

Using Alchemy

  1. Alchemy and Metamask setup
  2. Initialize a project
  3. Write a contract in contracts called HelloWorld.sol
  4. Connect Alchemy and Metamask to the project
  5. Compile the contract
    • $ truffle compile
  6. Create a new file in migrations called 2_deploy_contracts.js
  7. Add the contents of the file file here: 2_deploy_contracts.js
  8. Deploy the contract to the blockchain
    • $ truffle migrate --network goerli

Go Back to steps

Now you have a working contract that is deployed on Alchemy. Next you should make a frontend for this. Follow this tutorial on creating a frontend for your smart contract.

Alchemy and Metamask setup

  1. Signup for an acount on Alchemy
  2. Create an app in Alchemy
  3. Switch Metamask to Goerli (or wherever the app is)
  4. Add ether from a faucet
  5. Test connection by checking the balance in Alchemy Composer

Go Back to steps

Initialize a project

  1. Create a folder for the project
  2. Open the project in VS Code
  3. Open ternimal
    • `ctrl + `` (ctrl + backtick)
  4. Initialie a project using
    • $ npm init -y
  5. $ Check if truffle is installed on your system
    • npm list -g
  6. If not installed then install
    • $ npm i -g truffle
  7. Create a new truffle project
    • $ truffle init
  8. Install wallet provider to connect to Alchemy
    • $ npm install @truffle/hdwallet-provider

Go Back to steps

Connect Alchemy and Metamask to the project

  1. IMPORTANT Create a .gitignore and add .env
  2. npm i dotenv
  3. To protect your secret keys add a .env file in the root directory.
  4. Copy the content for .env from the format given below
  5. Go to the Alchemy dashboard
  6. Click on "View Key" for the Driver Registration app
  7. Copy the "HTTPS" link
  8. Replace API_URL in .env
  9. Follow this official tutorial by MetaMask on How to reveal your Secret Recovery Phrase
  10. Copy the 12-word phrase
  11. Replace MNEMONIC in .env
  12. Save .env
  13. Open truffle_config.js
  14. Delete all the contnets of this file
  15. Replace the file with the contnet fo this file: truffle_config.js

Go Back to steps

Files

HelloWorld.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract HelloWorld {
    string public message;

    constructor(string memory _message) {
        message = _message;
    }

    function updateMessasge(string memory _message) public {
        message = _message;
    }
}

Go Back to steps

.env

API_URL = "https://eth-ropsten.alchemyapi.io/v2/your-api-key"
MNEMONIC = "your-metamask-seed-phrase"

Go Back to steps

truffle-config.js

require('dotenv').config()
const HDWalletProvider = require('@truffle/hdwallet-provider')
const { API_URL, MNEMONIC } = process.env

module.exports = {
  networks: {
    development: {
      host: '127.0.0.1',
      port: 7545,
      network_id: '*',
    },
    goerli: {
      provider: function () {
        return new HDWalletProvider(MNEMONIC, API_URL)
      },
      network_id: 5,
      gas: 4000000, //4M is the max
    },
  },
  compilers: {
    solc: {
      version: '0.8.0',
    },
  },
}

Go Back to steps

2_deploy_contracts.js

const HelloWorld = artifacts.require('HelloWorld')
const initMessage = 'Hello world!'

module.exports = function (deployer) {
  deployer.deploy(HelloWorld, initMessage)
}

Go Back to steps

hello-smart-contract-alchemy-tutorial's People

Contributors

abhyaskanaujia avatar

Watchers

 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.