Expanding Access to Web3 With SMS

Conflux Network
Conflux Network
Published in
8 min readJul 11, 2020

--

Smart Contract Interaction Through SMS Messaging Using Conflux Network and Chainlink

The power of Web3 technology is that it indiscriminately grants permissionless access to a global ecosystem for finance, accountability, and participation. In order to maintain a tenet of unrestricted access, user connectivity should hold a high value while developing Web3 ecosystems. Otherwise, this world-changing technology has the potential to widen the existing socio-economic gaps because it is only accessible by certain segments of society. In order to interact with a Web3 ecosystem like Conflux Network, an internet connection is required regardless of the device type. In light of the need for connectivity, smartphone devices connected via broadband internet are seen as the key to bringing Web3 technology to the general public through a plethora of applications.

SMS For Wider Access and Adoption

While smartphone device usage continues to rise, an approach based solely on smartphone internet capabilities leaves certain segments of the world behind. According to a 2019 Pew Research Center study on global smartphone ownership, smartphone ownership varies widely across advanced and emerging economies. For example, South Korea reported 95% of adults own smartphones and the other 5% own a non-smartphone mobile phone, and in Nigeria it was reported to be 39% and 44%, respectively. Additionally, another 2019 Pew Research study on the demographics of smartphone ownership in the US shows that ~15% of the US population only has access to non-smartphone cell phones with percentages increasing depending on age, income, education, and residence environment.

If Web3 access were only available through smartphone apps and internet connectivity, significant portions of the global population would be left behind. In order to bring Web3 to users who only have access to non-smartphone cellular devices, text-based SMS communication can bridge the lack of app-based capabilities. By developing technology for on-chain interactions through SMS, Web3 ecosystems can be accessed from urban communities in advanced countries to rural environments in emerging societies.

Demonstration Architecture

The following section details a very simple architecture of using a smart contract deployed on Conflux Network, Chainlink oracles, and a SMS gateway from Twilio to create on-chain interactions via SMS. All of the code for the following demonstration can be found on Github: CFX + Chainlink Demo. Additionally, the Github repository has more detailed startup and installation instructions as well as additional links to Chainlink documentation.

When an on-chain event is emitted at a specific contract address, send the information in the event to a phone via SMS. Additionally, when an SMS is sent to a specific phone number, take the parameters in the SMS message and use it as the input parameters for a smart contract function call. Both SMS inputs and outputs are funneled to and from a smart contract on the Conflux Network through a Chainlink oracle node.

General connections diagram for setting up interaction between Conflux Network and SMS messaging services using Chainlink.

The smart contract has three functions — one for emitting an event to trigger the Chainlink request (job), and two callable functions to update or view the on-chain state. There are many further developments that will be explored later on.

pragma solidity ^0.6.0;

contract test_oracle {
uint256 private result;

event NewEvent(address caller, uint256 current);

constructor() public {
result = 0;
}

function getNum() external view returns (uint256) {
return result;
}

function sendEvent() external {
emit NewEvent(msg.sender, result);
}

function update(uint256 _result) external {
result = _result;
}
}

The next steps involve various Chainlink components — the external initiator (EI), the node (CL node), and external adapters (EA). The EI is a server that is customized to monitor a Conflux Network endpoint for events at a specific contract address. Once an on-chain event is detected, the EI triggers a corresponding job run on the CL node. In this case, the EAs are Node.js/Express servers used to interface with and send data to the Twilio API as well as pass information back to Conflux Network.

However, in general, EAs can also be serverless functions and created in any programming language. The code for the external initiator can be found at the Github repository: Conflux-Network-Global/external-initiator, and the external adapters can be found in the CFX + Chainlink Demo repository.

Sequence diagram illustrating the two interactions with the system and how the various pieces connect together when either interaction is made.

Once each piece is running, multiple bridges and job specifications must be created on the CL node to connect all of the pieces together as shown in the sequence diagram. There are three bridges to setup to allow Chainlink jobs to interface with the external adapters.

  • TwilioBridge: Used to send parameters to Twilio API for outputting SMS
  • TwilioCheck: For polling the Twilio API for new messages
  • cfxSendTx: Returning transactions to the smart contract on Conflux Network

The first job specification is used to initialize the external initiator and passes information on which endpoint and contract address to monitor. When this job is started, the external initiator will begin regularly polling the Conflux Network endpoint for events at the specific contract address. Once the external initiator detects an on-chain event, it will trigger the job’s task section where the information is sent to the TwilioBridge adapter for communicating with the Twilio SMS API.

{
"initiators": [
{
"type": "external",
"params": {
"name": "cfx",
"body": {
"endpoint": "cfx-mainnet",
"addresses": ["0x8aa73841e0a0e6e816b2c66c9c5ed1e144ad8cbb"]
}
}
}
],
"tasks": [
{"type": "TwilioBridge"}
]
}

The second job specification is used to monitor for new incoming SMS messages. In order to do this, the Chainlink node uses a CRON job to regularly query the Twilio external adapter (TwilioCheck) which checks the Twilio API. The returned information is passed to Conflux Network external adapter (cfxSendTx) which will send any found transactions on to the smart contract.

{
"initiators": [
{
"type": "cron",
"params": {
"schedule": "CRON_TZ=UTC */30 * * * * *"
}
}
],
"tasks": [{ "type": "TwilioCheck" }, { "type": "cfxSendTx" }]
}

Assuming that everything is set up and functioning correctly, by triggering the sendEvent() function in the smart contract on Conflux Network, an SMS is sent with the details of the event. By replying to the Twilio phone number with “update 14”, the SMS triggers the update() function in the smart contract and uses the second parameter as the function input. Currently, the demonstration supports a single phone number, but additional work could be done to handle additional numbers for various Conflux Network addresses.

Development Opportunities

Overall, this is a rather simple demonstration of connecting a Conflux Network smart contract with SMS interaction capabilities. There are many different areas of improvement ranging from the smart contract to security to the SMS integration. The following section will discuss some ideas and the potentials for each one — but there are many more ways to be creative with the basic functionality established above.

To a casual reader, it may initially seem easier to wrap all of the Chainlink components together into a single centralized server that monitors the endpoint and interfaces between the API and Conflux Network. However, doing so would defeat the whole purpose of using a smart contract as it removes its most valuable properties of not having to trust any counterparty in the transaction. If a single server is used, transactions are now subject to a single point of failure, whether that be downtime, manipulation or accidental human error by the host of the server.

Chainlink extends the security and reliability guarantees provided by the blockchain to also include the process of verifying and delivering external data to smart contracts in a decentralized, manipulation resistant, and highly available manner. By using Chainlink, more oracle nodes could be set up by others to verify that the on-chain events actually occurred and that the incoming SMS messages from the API are correct — thus creating an environment where it is safe for anyone to use not just a single user. And on a larger scale, Chainlink can be used to create the necessary connections for a safe and consistent interaction with on-chain protocols via SMS for anyone in the world.

The most exciting improvements would be on the smart contract end of the system. A powerful addition could be the use of contract-based wallets. This allows for a user to programmatically allow an external party to perform transactions as a part of the SMS integration without requiring the handling of a sensitive private key. Instead of requiring an app or a website to send transactions, a user would be able to send transactions with a simple SMS message. A more advanced concept could be to create a contract-based wallet that includes an interface with other on-chain DeFi protocols like DEXs or lending protocols to allow interaction with decentralized finance (DeFi) through SMS.

By using Conflux Network and Chainlink, there are limitless possibilities — such as the medical diagnosis AI application powered by a user data economy discussed in a previous article. However, Web3 and blockchain technology has the potential to achieve a more lofty ambition of changing oft-biased human-organized systems to fairer code-based, decentralized systems. While building a large ecosystem with many different services is important, it is just as vital to ensure that equal opportunity exists to access those services. SMS technology is not a coverall for access, but it is a good first step towards bringing Web3 access to people — regardless of location, age, or socio-economic status.

Written by Conflux Network’s Research Engineer Aaron Lu

Conflux Network Technical Chainlink Integration Demo & Q&A

Join us for a technical integration demo & Q/A with Aaron Lu of Conflux Network.

The meetup will show a technical demo of Conflux’s integration with Chainlink, followed by a Q&A discussion.

Watch live on the Chainlink Official Youtube: https://www.youtube.com/chainlinkofficial

When: Thu, Jul 16, 1:00 PM (EDT)

RSVP HERE

About Chainlink

Chainlink is a decentralized oracle network that enables smart contracts to securely access off-chain data feeds, web APIs, and traditional bank payments. It is well known for providing highly secure and reliable oracles to large enterprises (Google, Oracle, and SWIFT) and leading smart contract development teams such as Polkadot/Substrate, Synthetix, Loopring, Aave, OpenLaw, Conflux, and many others.

Learn more by visiting the Chainlink website, Twitter, or Telegram. If you’re a developer, visit the developer documentation or join the technical discussion on Discord.

About Conflux Network

The most endorsed DLT project in China, Conflux Network is an open-source, layer-1 blockchain protocol delivering heightened scalability, security, and extensibility for the next generation of open commerce, decentralized applications, financial enterprises, and Web 3.0. Conflux Network is overseen by a global team of world-class engineers and innovative computer scientists. Fostering entrepreneurship and innovation, Conflux unites startups and enterprises across industries and continents to promote decentralized collaboration in advancing blockchain technologies for real-world solutions. Founded in 2018, Conflux has raised $35 million in capital from prominent investors including Sequoia China, Metastable, Baidu Ventures, F2Pool, Huobi and IMO Ventures.

To discuss Conflux Network and join our community, visit our official channels:

Twitter | Discord | Telegram | GitHub

--

--

Conflux Network
Conflux Network

Conflux is a PoW + PoS hybrid first layer consensus blockchain for dApps that require speed at scale, without sacrificing decentralization.