Following the official tutorial in the Alchemy GitHub. This tutorial is not available on the official docs website but only on GitHub.
- Alchemy and Metamask setup
- Initialize a project
- Write a contract in contracts called HelloWorld.sol
- Connect Alchemy and Metamask to the project
- Compile the contract
- $
truffle compile
- $
- Create a new file in migrations called 2_deploy_contracts.js
- Add the contents of the file file here: 2_deploy_contracts.js
- Deploy the contract to the blockchain
- $
truffle migrate --network goerli
- $
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.
- Signup for an acount on Alchemy
- Create an app in Alchemy
- Switch Metamask to Goerli (or wherever the app is)
- Add ether from a faucet
- Test connection by checking the balance in Alchemy Composer
- Create a folder for the project
- Open the project in VS Code
- Open ternimal
- `ctrl + `` (ctrl + backtick)
- Initialie a project using
- $
npm init -y
- $
- $ Check if truffle is installed on your system
npm list -g
- If not installed then install
- $
npm i -g truffle
- $
- Create a new truffle project
- $
truffle init
- $
- Install wallet provider to connect to Alchemy
- $
npm install @truffle/hdwallet-provider
- $
- IMPORTANT Create a .gitignore and add .env
npm i dotenv
- To protect your secret keys add a .env file in the root directory.
- Copy the content for .env from the format given below
- Go to the Alchemy dashboard
- Click on "View Key" for the Driver Registration app
- Copy the "HTTPS" link
- Replace
API_URL
in .env - Follow this official tutorial by MetaMask on How to reveal your Secret Recovery Phrase
- Copy the 12-word phrase
- Replace
MNEMONIC
in .env - Save .env
- Open truffle_config.js
- Delete all the contnets of this file
- Replace the file with the contnet fo this file: truffle_config.js
// 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;
}
}
API_URL = "https://eth-ropsten.alchemyapi.io/v2/your-api-key"
MNEMONIC = "your-metamask-seed-phrase"
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',
},
},
}
const HelloWorld = artifacts.require('HelloWorld')
const initMessage = 'Hello world!'
module.exports = function (deployer) {
deployer.deploy(HelloWorld, initMessage)
}