Last active
July 25, 2022 01:58
-
-
Save tatsuyasusukida/38db3efe12e4701998e2db3d4d2b7961 to your computer and use it in GitHub Desktop.
👷 How to deploy smart contracts in Mumbai
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API_URL="https://matic-mumbai.chainstacklabs.com" | |
PRIVATE_KEY="0000000000000000000000000000000000000000000000000000000000000000" | |
POLYGONSCAN_API_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
CONTRACT_ADDRESS="0x0000000000000000000000000000000000000000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() | |
async function main () { | |
try { | |
const HelloWorld = await ethers.getContractFactory('HelloWorld') | |
const helloWorld = await HelloWorld.deploy('Hello World!') | |
console.info(`Contract deployed to address: ${helloWorld.address}`) | |
} catch (err) { | |
console.error(err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() | |
require('@nomiclabs/hardhat-ethers') | |
require('@nomiclabs/hardhat-etherscan') | |
module.exports = { | |
solidity: "0.8.9", | |
defaultNetwork: 'maticmum', | |
networks: { | |
hardhat: {}, | |
maticmum: { | |
url: process.env.API_URL, | |
accounts: [`0x${process.env.PRIVATE_KEY}`], | |
}, | |
}, | |
etherscan: { | |
apiKey: process.env.POLYGONSCAN_API_KEY, | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity >=0.8.9; | |
contract HelloWorld { | |
event UpdatedMessages (string oldMessage, string newMessage); | |
string public message; | |
constructor (string memory initMessage) { | |
message = initMessage; | |
} | |
function update (string memory newMessage) public { | |
string memory oldMessage = message; | |
message = newMessage; | |
emit UpdatedMessages(oldMessage, newMessage); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {abi} = require('../artifacts/contracts/HelloWorld.sol/HelloWorld.json') | |
main() | |
async function main () { | |
try { | |
const {API_URL, PRIVATE_KEY, CONTRACT_ADDRESS} = process.env | |
const provider = new ethers.providers.JsonRpcProvider(API_URL) | |
const wallet = new ethers.Wallet(PRIVATE_KEY, provider) | |
const contract = new ethers.Contract(CONTRACT_ADDRESS, abi, wallet) | |
const message = await contract.message() | |
console.info(`The message is: ${message}`) | |
console.info(`Updating the mesaage...`) | |
const tx = await contract.update(message + '!') | |
await tx.wait() | |
const newMessage = await contract.message() | |
console.info(`The message is: ${newMessage}`) | |
} catch (err) { | |
console.error(err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "mumbai-smart-contract", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"compile": "hardhat compile", | |
"deploy": "hardhat run scripts/deploy.js", | |
"interact": "hardhat run scripts/interact.js", | |
"verify": "source .env && hardhat verify $CONTRACT_ADDRESS \"Hello World!\"" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"@nomiclabs/hardhat-ethers": "^2.1.0", | |
"@nomiclabs/hardhat-etherscan": "^3.1.0", | |
"ethers": "^5.6.9", | |
"hardhat": "^2.10.1" | |
}, | |
"dependencies": { | |
"dotenv": "^16.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment