The following guide will explain how to deploy an ERC-20 smart contract, sync and watch contract events, and saving the data into the Moralis database:
For this example, we deployed an ERC-20 contract with the symbol MOR with "ERC20PresetMinterPauser.sol" using our local Ganache instance, Remix, and MetaMask. We also want to track all "_mint" events for our contract (keep in mind that "_mint" events in OpenZeppelin emits a transfer event, more info HERE).
Replace the content in "frpc.ini", the code assumes that your Ganache instance is hosted at port 7545.
Then you just need to run:
./frpc -c frpc.ini (Linux)
frpc.exe -c frpc.ini (Windows)
To verify the connection made is correct, just refresh the page (you can use F5) and you should now see the "CONNECTED" status:
Syncing and Watching Contract Events From Moralis
The next step will be to create a new plugin in the admin panel to sync and watch contract events:
"description" - Enter "Sync MOR Transfer Events". It's a small description for us to keep track of all the plugins we add to our instance.
"topic" - We use "Transfer(address,address,uint256)", but you can also use the sha3 topic "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef".
"abi" - Our abi includes three inputs: from, to, and value. We get this abi directly from Remix.
"address" - "0x4F27558d3F86670a9E2EfF294b7d10600266533F" (our MOR contract address).
"tableName" - "MORTransferEvent", it's the name of the table that will be created in our database with all the events.
To get the abi from Remix, just go to the "Solidity Compiler" tab, choose the "ERC20PresetMinterPauser.sol" contract and click on the abi icon. The full abi will be copied to the clipboard, make sure you use only the abi for the event you are syncing:
Make sure your "frp-ganache" is connected, and you will see the table continuously being filled with historical and real-time data.