Novel Blockchain Scripts
- Novel Admin Wallet (owned by Novel) creates a GSN Paymaster, which will fund all transactions
- Brand Wallet (ex: General Mills) creates and deploys a Collection Contract, using the Paymaster to pay the gas fee
- Customer Wallet (buying the NFT) will perform a gasless mint function, funded by the Novel Paymaster
- Go to ChainList.org and search for "MATIC".
- Click "Add to MetaMask" on both the MainNet and the TestNet
- Click "Approve" in your MetaMask Wallet
- Click MetaMask extension
- Click on your account image on the very top right
- Click "Create Account"
- Name the following accounts:
- Novel Admin Wallet: will hold MATIC and fund the Paymaster
- Brand Wallet: this will be owned by the brand (ex: General Mills) in production, but in your test environment, we are going to pretend we are also a brand.
- Customer Wallet: this will be the Torus wallet automatically created for the NFT Buyer (customer). It will hold no MATIC. We are mocking it in our local setup, by creating a wallet in MetaMask
- Switch to the "Novel Admin Wallet"
- Click on "..." on top right
- Click "Account Details"
- Click "Export Private Key"
- Enter your password
- Copy they key to someplace secure to use in next step
- Go back to the account, and copy the "Public Address" by clicking the little "Copy" button next to
0x....
- Repeat for all 3 wallets
-
Make a copy of
.env.template
into.env
-
Substitute the following values:
NOVEL_ADMIN_WALLET_PRIVATE_KEY
: Export from MetaMask using steps aboveBRAND_WALLET_PRIVATE_KEY
: Same as above, but for the Brand Wallet"
-
Copy the public keys on the wallets (using steps in previous section) to:
CUSTOMER_WALLET_PUBLIC_KEY
NOVEL_ADMIN_WALLET_PUBLIC_KEY
-
Go to PolygonScan and create an account. Click on your name for the dropdown, and click API Keys. Copy that key into
ETHERSCAN_API_KEY
-
Set up your
RPC_MAINNET_URL
. By default it is Polygon RPC Public Endpoint. You might want to switch out with Alchemy Private endpoint for reliability- Go to Alchemy Dashboard - sign up for an account of get added to Novel's
- Click "Create App"
- Name it "Novel - Local Testnet"
- Choose "Development" for "Environment"
- Choose "Polygon" for "Chain"
- Choose "Polygon Mumbai" for "Network"
- Create another app
- Name it "Novel - Local Mainnet"
- Choose "Production" for "Environment"
- Choose "Polygon" for "Chain"
- Choose "Polygon Mainnet" for "Network"
- Get keys for Alchemy RPC
- Click on the Testnet app and click "View API Key"
- Copy the HTTP endpoint (ex:
https://polygon-mumbai.g.alchemy.com/v2/KEYISHERE
) intoRPC_MAINNET_URL
into the .env file - Repeat for the testnet, setting
RPC_TESTNET_URL
You must compile all the solidity contracts before running commands. Recompile every time you change a solidity contract.
Just run:
yarn compile
We have some yarn shortcuts to define the network we run command.
Make sure you switch into the blockchain
folder.
All the commands are actually defined in hardhat as tasks.
You can do yarn <network> --help
to get the most current docs on the commands available
Supported Networks are:
mumbai
: the testnetpolygon
: the mainnetlocal
: hardhat hardhat local chain
Ane example command would like like this:
yarn mumbai deploy-paymaster
Command:
yarn <network> deploy-paymaster`
Example:
yarn polygon deploy-paymaster`
Should return a contract address, such as, 0xB2Aa3A38FD53bC7F2e3f4e97BeE222C3bbb77209
and write it to a file called paymaster.polygonMumbai.json
.
Note that it appends the network name.
The purpose of this file is to no deploy the paymaster multiple times (it only needs to be deployed once).
In production, we will store the paymaster to a central location (ex: S3)
You can verify the paymaster deployed successfully by going to PolygonScan (for mainnet) or PolygonScan Mumbai (for testnet).
You will see a single transaction labeled Contract Creation
.
If you want to verify the paymaster automatically, also pass the --verify
flag. Otherwise use the verify-paymaster
task below.
Command:
yarn <network> verify-paymaster
Example:
yarn polygon verify-paymaster
Will verify the contract on PolygonScan. You will see a Green Checkmark under "Contract" if the verification was successful. It also shows the code for the contract on Polygon Scan!
Additionally, you can connect your wallet right in PolygonScan, and run Read/Write commands with a very nice GUI.
Command:
yarn <network> fill-paymaster --ethtotransfer <amount of matic here>`
Example:
yarn polygon fill-paymaster --ethtotransfer 10
We will transfer some MATIC to the paymaster so that it can pay for customer transactions (ex: minting) and brand transactions (ex: contract creation)
Before doing this you have to fill your wallet with MATIC.
If you're on testnet (mumbai), you can use the faucet. It gives you .5 MATIC at a time. You need to wait about a minute between retries.
Start with filling .25 MATIC, so that it also has enough gas to run the fill transaction.
On mainnet