In it's own terminal / command line, run:
git clone https://github.com/Nedick/hardhat-nft-marketplace
cd hardhat-nft-marketplace
yarn
git clone https://github.com/Nedick/nextjs-moralis-nft-marketplace.git
cd nextjs-moralis-nft-marketplace
yarn
After installing dependencies, start a node on it's own terminal with:
yarn hardhat node
Setup your event moralis. You'll need a new moralis server to get started.
Sign up for a free account here.
Once setup, update / create your .env
file.
NEXT_PUBLIC_APP_ID=XXXX
NEXT_PUBLIC_SERVER_URL=XXXX
moralisApiKey=XXX
moralisSubdomain=XXX
masterKey=XXX
chainId=31337
With the values from your account.
Then, in your ./package.json
update the following lines:
"moralis:sync": "moralis-admin-cli connect-local-devchain --chain hardhat --moralisSubdomain XXX.usemoralis.com --frpcPath ./frp/frpc",
"moralis:cloud": "moralis-admin-cli watch-cloud-folder --moralisSubdomain XXX.usemoralis.com --autoSave 1 --moralisCloudfolder ./cloudFunctions",
Replace the XXX.usemoralis.com
with your subdomain, like 212ug12gYourSubDomain.usemoralis.com
and update the moralis:sync
script's path to your instance of frp
(downloaded as part of the Moralis "Devchain Proxy Server" instructions mentioned above)
yarn global add moralis-admin-cli
Optionally: On your server, click on "View Details" and then "Devchain Proxy Server" and follow the instructions. You'll want to use the
hardhat
connection. (This instruction is for legacy UI)
- Download the latest reverse proxy code from FRP and add the binary to
./frp/frpc
. - Replace your content in
frpc.ini
, based on your devchain. You can find the information on theDevChain Proxy Server
tab of your moralis server.
In some Windows Versions, FRP could be blocked by firewall, just use a older release, for example frp_0.34.3_windows_386
Mac / Windows Troubleshooting: https://docs.moralis.io/faq#frpc
Once you've got all this, you can run:
yarn moralis:sync
You'll know you've done it right when you can see a green connected
button after hitting the refresh symbol next to DISCONNECTED
. You'll want to keep this connection running.
Anytime you reset your hardhat node, you'll need to press the RESET LOCAL CHAIN
button on your UI!
In a separate terminal (you'll have a few up throughout these steps)
Run yarn moralis:cloud
in one terminal. If you don't have moralis-admin-cli
installed already, install it globally with yarn global add moralis-admin-cli
.
Note: You can stop these after running them once if your server is at max CPU capactity.
If you hit the little down arrow in your server, then hit Cloud Functions
you should see text in there.
Make sure you've run yarn moralis:sync
from the previous step to connect your local Hardhat devchain with your Moralis instance. You'll need these 3 moralis commands running at the same time.
node addEvents.js
Finally, go to View Details
-> Sync
and hit Add New Sync
-> Sync and Watch Contract Events
Add all 3 events by adding it's information, like so:
- ItemListed:
- Description: ItemListed
- Sync_historical: True
- Topic: ItemListed(address,address,uint256,uint256)
- Abi:
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "seller",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "nftAddress",
"type": "address"
},
{
"indexed": true,
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "price",
"type": "uint256"
}
],
"name": "ItemListed",
"type": "event"
}
5. Address: <YOUR_NFT_MARKETPLACE_DEPLOYED_ADDRESS_FROM_HARDHAT>
6. TableName: ItemListed
You can add the canceled and bought events later.
Back in the contract directory, run:
yarn hardhat run scripts/mint-and-list.js --network localhost
And you'll now have an NFT listed on your marketplace.
At this point, you'll have a few terminals running:
- Your Hardhat Node (From Contracts repo)
- Your Hardhat Node syncing with your moralis server (From Front-end repo)
- Your Cloud Functions syncing (From Front-end repo)
And you're about to have one more for your front end (From Front-end repo).
yarn run dev
And you'll have your front end, indexing service running, and blockchain running.