This page may contain legacy content

To get our most up-to-date content please access our documentation

April 25, 2022

How to Get Blockchain SMS Notifications

Table of Contents

Email and SMS notifications are popular communication methods used in almost every industry. Today, one can receive an SMS for just about anything, such as a transaction confirmation after making a purchase. As blockchain transactions are becoming increasingly popular, wouldn’t it be great if a user could get blockchain SMS notifications? Fortunately, we can enable this feature easily in our Web3 apps, and we can do so in just a few steps:

  1. Deploy your smart contract with Remix.
  2. Create your Moralis server.
  3. Use Moralis’ “Sync” feature to sync and index smart contract events.
  4. Complete the initial Twilio and OneSignal setups.
  5. Use Moralis’ cloud functions to establish communication between smart contract events and OneSignal.

We encourage you to join us in this “how to get blockchain SMS notifications” quest as we take on an example project. By doing so, you will learn to get blockchain SMS notifications to track on-chain events. The latter can be used by dev teams or for notifying users of Web3 apps. Along the way, you will learn how to use several phenomenal tools. These include Twilio, OneSignal, Remix, and Moralis. 

The first one will enable us to obtain a phone number to send blockchain SMS notifications from. The second tool will serve to send push requests. With Remix, we will be able to edit and deploy our Web3 contract. Last but not least, we will use Moralis – the pinnacle of the current Web3 tech stack – to tie it all together. Fortunately, this “Firebase for crypto” platform offers neat ways to handle all of your Web3 backend needs. Among others, it enables you to index the blockchain effortlessly. Moreover, with this ultimate Web3 backend platform on your side, you have cross-chain and cross-platform interoperability at your disposal. So, create your free Moralis account now to get started!    

How to Get Blockchain SMS Notifications – Example Project

As we move forward, we will first do a quick demo of our example project to see blockchain SMS notifications in action. That will provide you with a clear picture of what to expect from our “how to get blockchain SMS notifications” tutorial. After this preview, we will open up Remix and deploy our “donation” smart contract. Then, we will make sure you learn how to complete the initial Moralis setup. The latter will be your gateway into Moralis’ SDK and all of the above-mentioned Moralis features. Next, we will show you how to use Moralis’ sync function and database, which plays a critical role in sending blockchain SMS notifications. Then, we will hand you over to one of Moralis’ experts, who will guide you through the remaining steps (four and five) of our “how to get blockchain SMS notifications” journey via a video tutorial. 

Blockchain SMS Notifications for On-Chain Events – Demo

Let’s first look at the screenshot below. In that screenshot, you’ll see us using “PolygonScan” to view our smart contract. Moreover, on the right is a preview of our phone’s display: 

Using PolygonScan’s interface, we get to enter the amount we want to donate. To confirm our donation, we need to click on the “Write” button. By doing so, the interface triggers our MetaMask extension, which prompts us to confirm our transaction:

We execute the transaction representing our donation by clicking on the “Confirm” button. So, as this on-chain event takes place, we receive a text message:

As a result, we can confirm that our blockchain SMS notifications are functioning properly.

Note: The entire code related to our example project awaits you on GitHub.

Blockchain SMS Notifications and Smart Contracts

Unless you’ve been living under a rock, odds are you’ve heard about Ethereum. As such, you know that it’s the leader among programmable blockchains. However, many other EVM-compatible (e.g., Avalanche, Polygon, BNB Chain, etc.) and non-EVM (e.g., Solana, Terra, etc.) alternatives are available. All programmable blockchains enable devs to create decentralized applications (dapps) on top of their networks. Moreover, smart contracts enable dapps to run according to protocols and execute automated actions properly. Also, they are the backbone of dapps. You should also keep in mind that whenever smart contracts do something meaningful, they emit events. Thus, we talk about smart contract events. In addition, we use the Solidity programming language to write contracts for EVM-compatible chains.

If we focus again on our project, a smart contract event serves as a trigger for our blockchain SMS notifications. Based on the above demo, you know that our example project revolves around donations. Furthermore, we are executing donation transactions on Polygon’s testnet (Mumbai). Accordingly, this is the chain we will focus on. Without further ado, let’s start with the first step of our “how to get blockchain SMS notifications” journey!

Step 1 – Deploy Your Smart Contract with Remix

The contract we created is called “ExampleDonationContract.sol“, and it’s also available on GitHub. You can follow along by copying the entire code into Remix. There, you will also be able to deploy it.

Looking at the screenshot above, you can see the details of our example smart contract inside Remix. We marked the “Donate” event that we’ll track and the “newDonation” function. Our contract also includes a payable address representing the owners who make donations. There’s also “constructor()”, which ensures the message value is sent to the owner. Moreover, you can see that the “Donate” event gives the address of a donor and the donated amount. Nonetheless, the “newDonation” function emits the “Donate” event. 

Once you are ready to deploy your smart contract, click “Deploy”. Make sure to follow our example and use the Mumbai testnet. You can use the video at the end of this article for more details.  

Blockchain SMS Notifications and Moralis

You’ve learned about Moralis and how it covers your blockchain-related backend needs at the beginning of this “how to get blockchain SMS notifications” article. You’ve also learned that you must create a Moralis server to utilize the platform’s power. Thus, we will focus our attention on that step. Then, we will be able to use the sync and cloud functions features. 

Step 2 – Create Your Moralis Server

For the second part of our “how to get blockchain SMS notifications” quest, let’s look at how you can create a Moralis server.

  1. Log In to Your Moralis Account – At this point, you probably already have your Moralis account ready. As such, just log in. However, if that’s not the case, use the “create your free Moralis account” link stated at the beginning of this guide.
  1. Create a Moralis Server – Inside your Moralis admin area (the “Servers” tab), click on “+ Create a new Server”:

Next, select “Testnet Server” from the drop-down menu. Then, you’ll need to enter your server’s details. Make sure to select Polygon’s testnet and click on “Add Instance” to spin up your server:

Step 3 – Use Moralis’ Sync Feature to Sync and Index Smart Contract Events

With your server up and running, you can access the sync feature via the “View Details” button: 

With your server’s details in front of you, you need to switch to the “Sync” tab:

Inside the “Sync” tab, you’ll notice the “No Sync Services Installed” message. The latter indicates that you are using a new server with no sync services set in place yet. To proceed, click on the “Add New Sync” button:

After clicking on the button, you’ll have two options:

Go with the “Sync and Watch Contract Events” option at the top of the drop-down menu. After selecting the correct sync option, you’ll get to configure your sync and watch smart contract events. This is quite straightforward, especially because you’ve already deployed your smart contract. You just need to copy and paste the smart contract details from Remix, which we will go further into below. 

Sync and Listen to Smart Contract Events – ChainId, Description, Sync-historical, and Topic

To make sure you get things right, we will guide you through all entry fields of your new “Sync”. First, select the correct network (the Mumbai testnet). Further, click on it to get a green checkmark (see the image below).

Note: If Mumbai is the only network you’ve selected when creating your Moralis server, it will be the only option available.

As far as “Description” goes, you can type whatever you want but feel free to follow our lead and go with “New Donation Watch”. Next, uncheck (click on the square) the “Sync-historical” data option, which is enabled by default. For our example project, past on-chain data are of no interest to us. Moreover, to properly fill out the “Topic” entry field, you need to get the following details from your smart contract:

After pasting the above-selected lines into the entry field, don’t forget to delete the variable names. You should only leave the variable types, which are “address” and “uint256”:

Sync and Listen to Smart Contract Events – ABI, Address, and TableName

With “Topic” in place, it is time to obtain your smart contract’s ABI. That detail is also available inside Remix once you’ve compiled your smart contract. Moreover, make sure you are on the second tab inside Remix, where you’ll see “copy ABI”. The latter is under the “Compilation Details” button:

After clicking on the above button, you can directly paste your smart contract’s ABI into the entry field next to “Abi” inside the “Sync” setup. However, there are parts of the ABI that you don’t need. As such, apply the necessary tweaks until you are left with the following:

Moving forward, the “Sync” setup requires your smart contract’s address, which is also available in Remix. Hence, return to Remix where you deployed your contract:

Inside the “Deployed Contracts” section, you will see the name of your smart contract and the “copy” icon on the right. Use it and then paste the address into the entry field next to “Address” inside your “Sync” settings:

As far as the “TableName” entry field goes, you can use whatever you want or follow our lead and enter “NewDonations”. Now that you’ve entered all the details, you can finally create your sync by clicking on the “Confirm” button. By doing so, you will replace the “No Sync Services Installed” message with your new sync:

Using Moralis Dashboard for Blockchain SMS Notifications

Moralis dashboard is essentially a database that enables you to index the blockchain. Furthermore, it comes with every Moralis server. To access it and view all tracked events, you need to close the above window first. Then, click on the arrow next to the “View Details” button. Finally, click on the “Dashboard” button:

Note: This article is based on the video tutorial below, where a Moralis expert uses an older version of the dashboard’s interface. However, the functionality of the new dashboard is the same.

On the left-hand side of your Moralis dashboard, you will see several classes. A “NewDonations” class should also be available (see the screenshot below). Based on its name, you can see that this class was created automatically according to our “TableName” entry. Further, inside this class, our “donation” smart contract’s events will be indexed. Then, we will use these indexed events to trigger blockchain SMS notifications. 

Steps 4 and 5 – Twilio, OneSignal, and Moralis’ Cloud Functions

As mentioned, it is time to hand your over into the capable hands of a Moralis expert. Starting at 5:27 of the video below, he will guide you through the rest of the steps. First, he’ll show you how to create a proper cloud function (“CloudFunction.js”). In addition, you’ll learn how to track the total amount of donations with a Google spreadsheet at 7:21. 

Next, you will learn more about practical messaging tools – Twilio (9:21) and OneSignal (10:18). Furthermore, he’ll also guide you through the initial setup for both of these tools. Hence, you’ll be able to use them to get blockchain SMS notifications. These two tools will play an important role; however, they need something to “link” them with our smart contract. This is where you’ll learn how to use a cloud function for that purpose (11:53). The letter will also enable you to customize the content of your blockchain SMS notifications. 

https://www.youtube.com/watch?v=PEILxU53-Zs

Note: You can also use the above video (starting at 21:56) to learn how to get blockchain email notifications. In that case, you will also want to learn how to use SendGrid (video above at 8:48). The latter does for emails what Twilio does for SMS. 

How to Get Blockchain SMS Notifications – Summary

By combining our instructions and the video tutorial above, you’ve had a chance to implement blockchain SMS notifications into your Web3 app. We hope you’ve taken on this example project and learned how to deploy smart contracts, work with Moralis, and use other excellent tools, such as Twilio and OneSignal. Moreover, if you’ve enjoyed this example project, we encourage you to visit the Moralis YouTube channel and the Moralis blog. There, you’ll find a ton of other useful tutorials and crypto topics. 

Some of the latest articles demonstrate how to add a Web3 connect wallet button to your website, build a play-to-earn game, use a Mumbai testnet faucet, claim an in-game NFT, and create a Binance NFT. Also, it teaches you everything you need to know about Web3 without MetaMask, Ethereum Name Service (ENS), and it answers the “what is Web2 and Web3?” question!

Whether you want to build your first dapp, create your own ERC-20 token, or dive into Unity Web3, the above two outlets have you covered. Furthermore, you can use these two platforms to become a Web3 developer. However, if you are eager to go full-time crypto as soon as possible, you should take a more professional approach. In that case, consider enrolling in Moralis Academy, where top-notch blockchain development courses await you. Aside from high-quality online classes, you will also get a personalized study path, expert mentorship, and membership inside one of the most incredible communities in the industry. With all that, Moralis Academy enables you to become a blockchain developer fast and with confidence. 

Market Data API
Build amazing trading and portfolio dapps with this Market Data API. Keep users engaged with up-to-date data!
Market Data API
Related Articles
October 16, 2022

Blockchain-Based Authentication – How to Integrate?

August 12, 2022

Moralis Projects – Web3 Magic Treasure Chest

October 20, 2023

Base Goerli Faucet – Get Free Base Testnet Tokens 

October 18, 2023

How to Set Custom Webhooks with Moralis Streams

November 9, 2022

Solana Smart Contract Examples for Developers

February 2, 2024

How to Build Dapps on Optimism in 5 Steps – Optimism API Guide

February 6, 2024

Blockchain Data Analytics – Turn Blockchain Data Into Engaging Insights & Analysis with Discovery API 

December 8, 2022

How to Get NFT Collections Using Python and React