npm init --yes
to initialize the project. If you don’t already have npm
installed, follow these instructions (we’ll also need Node.js so download that too!).package.json
:polygon-smart-contract-tutorial
project run:polygon-smart-contract-tutorial
project folder, run:Create a basic sample project
:hardhat.config.js
file for us along with a couple of folders with sample code we can work with, including contracts
, scripts
, and test
.contracts/Greeter.sol
, we can see our example smart contract.^0.8.0
means that any minor version from 0.8.0 and upwards is fair to use!contract
syntax is very similar to working with classes or objects in other languages.greeting
. It is a string. Because it is marked with the private
modifier, only the contract itself has permissions to modify it. Although the data is still visible and public on the blockchain, other contracts and accounts will not be able to access or modify a private variable.public
modifier.Greeter
constructor, we expect a string _greeting
to be passed in when the contract is deployed. We then log to hardhat console, and then write the _greeting
string to the blockchain by setting it to the state variable greeting
.greet
.greeting
variable.setGreeting
is a write function that will cost gas for users to execute because it modifies the greeting
variable stored on the blockchain. Similar to the logic in the constructor, it takes in one string input and uses that to update the smart contract state variable.https://polygon-mumbai.g.alchemy.com/v2/Ed7AeuPuIgo6fNDi49TDy_x4UBymLBsJ
0x...
at the top..env
file in the root directory of our project, and add your MetaMask private key and HTTP Alchemy API URL to it..env
or it won't be recognized as an environment file. Do not name it process.env
or .env-custom
or anything else..env
file should look like this:dotenv
module inside our hardhat.config.js
file to do so.hardhat.config.js
with the following code snippet:dotenv
, we can access variables defined in our .env
file by using process.env
.mumbai
that uses the Alchemy HTTP URL and our MetaMask account to talk to the blockchain.compile
task is one of the built-in hardhat tasks.0x8Fab93D28e52a93d4b00E25Eaa04B64223382f89
) and create a new line in your .env
file to keep track of it for the next step..env
file should have at least these three environment variables defined:.deploy()
function.scripts
folder, creates a file called scripts/greet.js
. Read through the comments to understand what's going on!process.env.ALCHEMY_API_KEY
, etc., to load environment variables. If you're getting errors related to this, there may be something off with your dotenv
dependency or hardhat.config.js
configurations. Retry Steps 12 and 13 to set up the dotenv
dependency again!.env
file from Step 9? We're going to add a few variable definitions, like this:.env
file so that the changes are persisted!npx hardhat run scripts/greet.js
Block Number
it was mined in, which From Address
initiated the transaction, which To Address
is the recipient of the transaction, how much Value
(in MATIC) exchanged hands, what the transaction fees were, and much more: