Starter Kits
An Polygon Starter Kit Tutorial containing React, @web3-react, Alchemy.
0. Environment Setup
Install fundamental environments, including node, web3, react, truffle, etc
\0. Environment Setup
Install GanacheใTruffle
Use Starter Kits build your DAPP right away!
An Polygon Starter Kit Tutorial containing React, @web3-react, Alchemy.
Developer Docs - A Polygon Starter Kit tutorial from Alchemy
Install ganache
Download Package from https://www.trufflesuite.com/ganache
Ganache Screenshot
granache is needed for dapp development on local blockchain, its capable of viewing txns informations, create workspace folder, deploy smart contracts and tracking its interface.
Install truffle
npm install -g truffle
truflle is used for develop, test, and deploy smart contracts.
More tutorials about truffle: https://learnblockchain.cn/docs/truffle/
\0. Environment Setup
Create your DAPP using Starter Kits Template
Quick Start
npx create-react-app {YOUR_PROJECT_NAME} --template polygon-starter-kit
cd {YOUR_PROJECT_NAME}
npm run start
(npx comes from npm 5.2+ or later)
Then fireup your browser and go to http://localhost:3000/
to check your application.
When you are preparing to deploy your project to production settings, use npm run build
to create a compressed bundle and deploy.
Immediate Configuration
There is no need for you to install or configurate tools like Webpack or Babel. They comes pre-configurated and hiddened, therefore you are provided with the full environment pack where you only need to worry about coding part.
Just create a project with the template, then you are good to go!
Create Application
You will need to use Node that is higher or equal to version 6 on your local computer(on server you don't have to). There is nvm(macOS/Linux) or nvm-windows to help you eaily switch between different Node versions.
Create a new application
npx create-react-app {YOUR_PROJECT_NAME} --template polygon-starter-kit
Then a new folder named {YOUR_PROJECT_NAME}
will be created under current folder location. The File structures under this new folder is as below:
{YOUR_PROJECT_NAME}
โโโ README.md
โโโ node_modules
โโโ package.json
โโโ migrations
โโโ .gitignore
โโโ public
โ โโโ favicon.ico
โ โโโ index.html
โ โโโ manifest.json
โโโ src
โโโ App.css
โโโ App.js
โโโ App.test.js
โโโ assets
โ โโโ icon-devx.svg
โ โโโ logo512.png
โ โโโ polygon-logo.svg
โโโ components
โ โโโ Contents
โ โ โโโ index.js
โ โโโ Footer
โ โ โโโ footer.css
โ โ โโโ index.js
โ โโโ Headers
โ โ โโโ index.js
โ โโโ Wallet
โ โโโ ConnectWallet.js
โ โโโ WalletInfo.js
โโโ contracts
โ โโโ Migrations.sol
โโโ hooks
โ โโโ index.js
โโโ index.css
โโโ index.js
โโโ lib
โ โโโ connectors
โ โโโ index.js
โโโ reportWebVitals.js
โโโ setupTests.js
โโโ truffle-config.js
\0. Environment Setup
Truffle Environment Configuration
truffle-config.js
const mnemonic = process.env.MNEMONIC;
const HDWalletProvider = require("@truffle/hdwallet-provider");
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*" // Match any network id
},
polygon: {
provider: new HDWalletProvider(mnemonic, process.env.POLYGON_RPC),
network_id: 137,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
},
mumbai: {
provider: new HDWalletProvider(mnemonic, process.env.POLYGON_MUMBAI_RPC),
network_id: 80001,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
}
Create .env
File under root folder
vim .env
MNEMONIC=" {YOUR_MNEMONIC OR YOUR_PRIVATE_KEY} "
POLYGON_RPC = " {PUBLIC_POLYGON_RPC} OR https://rpc-mainnet.matic.network"
POLYGON_MUMBAI_RPC = " {PUBLIC_POLYGON_MUMBAI_RPC} or https://rpc-mumbai.maticvigil.com/"
More about PUBLIC_RPC
please reference on๏ผDevelopment Docs
1.Project Structure
Polygon-Starter-Kit Project Template Introduction, and how to utilize different modules in it.
1.Project Structure
Project Structure
Polygon-Starter-Kit Project Structure is as below
{YOUR_PROJECT_NAME}
โโโ README.md
โโโ node_modules
โโโ package.json
โโโ migrations
โโโ .gitignore
โโโ public
โ โโโ favicon.ico
โ โโโ index.html
โ โโโ manifest.json
โโโ src
โโโ App.css
โโโ App.js
โโโ App.test.js
โโโ assets
โ โโโ icon-devx.svg
โ โโโ logo512.png
โ โโโ polygon-logo.svg
โโโ components
โ โโโ Contents
โ โ โโโ index.js
โ โโโ Footer
โ โ โโโ footer.css
โ โ โโโ index.js
โ โโโ Headers
โ โ โโโ index.js
โ โโโ Wallet
โ โโโ ConnectWallet.js
โ โโโ WalletInfo.js
โโโ contracts
โ โโโ Migrations.sol
โโโ hooks
โ โโโ index.js
โโโ index.css
โโโ index.js
โโโ lib
โ โโโ connectors
โ โโโ index.js
โโโ reportWebVitals.js
โโโ setupTests.js
โโโ truffle-config.js
migrations
is used to contain JS scripts for smart contract migration and deploymentsrc
DAPP Client source codesrc/contracts
For containingsmart contract
๏ผand its also the contract location pointer in the truffle configurationsrc/abis
for containing abi files after Truffle Compilationhooks/index.js
initializeProvider
โs request hook in@web3-react