In the apps\full-stack-typescript-api\src\functions folder, create the following:
Updateapps\full-stack-typescript-api\src\functions\moralis\index.ts to be:
The new function receives a data payload of type addressand queries the Etheruem blockchain for the address' Ethereum balance.
Updateapps\full-stack-typescript-api\src\main.ts to include the new function.
The main.ts file is our primary entry point for our functions and needs to be updated so that our new function is included when the project is built.
Build the functions
Run the following command to build the functions application:
nx build full-stack-typescript-api
Deploy functions
Run the following command to deploy new and updated functions:
firebase deploy --only functions
Update the frontend application for new API interaction
Now that we've created a cloud function for interacting with the Ethereum blockchain, we need to update the frontend application to integrate with the new function.
Generate a Moralis service library
Run the following command to generate a new Moralis service libary:
nx g lib --name=moralis --directory=services
Create Moralis service
Run the below command to create the Moralis service:
The following files will be generated:
Delete the services-moralis.module.ts file.
Update the index.ts file to remove the module export.
Run the below command to create the Account Service
Update the index.ts file to export the account service file.
Update MoralisService
Updatelibs\services\moralis\src\lib\moralis.service.ts to include:
Create Web3 view
Feature workflow should be followed as described here: Feature workflow
Update web3.component.ts
Update web3.component.html
Further improvements
The onGetBalance function currently exposes the Moralis API key and should not be deployed to production environments. To secure this function and keep secrets, secret, the Secret Manager API workflow should be followed to improve and secure the function from abuse.