A simple demonstration of connecting Helium Network and Filecoin (using Powergate) that has the potential to facilitate IoT and decentralized storage connectivity. The token conversion is handled by a server that monitor a Conflux Network smart contract that handles basic record keeping.
Conflux Network + Javascript SDK
Filecoin Powergate + Javascript SDK
Helium Wallet CLI
Sequence diagram illustrating the communication between various components in order for HNT tokens to be converted to FIL tokens
cd powergate/docker
make localnet
Note that localnet
means it is only operating in a test environment. For deployment, Powergate can be setup to connect with the Filecoin testnet.
- Setup the Helium CLI and obtain a wallet using:
./target/release/helium-wallet create basic
- Optional: Deploy the smart contract on Conflux Network using the
contract/deploy.js
file. To do this, thecontract
folder must have a.env
file with:
PRIVATE_KEY=<insert a Conflux private key>
- Start the
server/index.js
file to being monitoring the Conflux Network smart contract. Make sure the configuration is properly set in the file. Default configuration:
const walletHNT = "13bmmTR2wVqYoj7E85dXgA8cVSbYP2bWD7YhBDNf9N2vm9DpQPf"; //HNT wallet address
const cfxContract = "0x8975f507a3d577aefbfefc929c9891b529fb1398"; //contract address
- Using the Helium CLI send HNT to the
walletHNT
address.
./target/release/helium-wallet pay --commit --payee 13bmmTR2wVqYoj7E85dXgA8cVSbYP2bWD7YhBDNf9N2vm9DpQPf=0.1
One the transaction is submitted, the transaction hash will be visible in the command line. Use the transaction hash to track the status on the Helium Blockchain Explorer.
- Once the transaction has been confirmed on the explorer, use the
deploy.js
file in thecontract
folder to submit transaction hash and corresponding Filecoin wallet address. Change these lines at the top:
const HNT_TRANSACTION = "k6fu3SqhF3X-kBaFWDtRxtTixLt1Nelsjlvmaia3z4s";
const FIL_ADDRESS = "t3q5z6nbg4mi4u46snrcznhtilwvxlaafcgpw7exouvvypb3vubltnjurg7jnm6frzwwsogjcmddyb3wd4u4qq";
- When the transaction is submitted, the server will see the event from the smart contract. Verify the HNT transaction was sent to the correct wallet, and release FIL to the corresponding address.
The smart contract - contract/swap.sol
- contains two functions. setRate
is for setting the conversion rate that the server uses to convert from HNT to FIL. FIL2HIL
emits an event containing the Helium transaction hash, the Filecoin address, and the rate. These parameters are picked up by the server for processing. Additionally, the smart contract tracks which transaction hashes have previously been submitted to prevent double-spending.
The server - server/index.js
- has five main functions. main
is the function that is called that contains all the other functions. setupLoop
sets up the necessary tokens to connect to a Powergate instance, and will loop to try again if a token is incorrect. cfxCheck
is used to monitor the Conflux Network smart contract for any new events. hntCheck
is used to verify the transaction on Helium and get the amounts from the transaction. amtCalc
uses the rate from the emitted event to calculate the amount of FIL tokens to send. sendFIL
will communicate with Powergate to send FIL tokens to the specified address.
This demonstration is only the initial steps and could be improved in many ways to make it ready for deployment.
Conceptual implementation of fully functioning application connecting IoT devices through Helium to storage provided by Filecoin
Helium has the capability to perform hashed timelock (HTLC) transactions. By using HTLC functionality, user transactions can be made even more secure. HTLC requires the submission of an extra "key" to unlock a transaction, otherwise the transaction reverts. This key can be setup in a Helium transaction and verified through the Conflux smart contract and prevent attackers from stealing someone else's transaction.
Currently, the only Powergate function used is the ability to send tokens. In the future, it may be possible to track token transaction hashes and make the token transfer work in both directions, rather from HNT to FIL only.
A more robust way to connect across three networks would be the use of oracle networks to securely pass information. Multiple nodes in the oracle networks could be required to confirm transaction activity in order to prevent any attackers from submitting transactions. Additionally, the rate
in the smart contract can be connected to price feeds from oracle networks.
The demonstration simply converts from one token to another. However, using an ERC-20 standard, HNT and FIL could be wrapped on Conflux as cHNT and cFIL. This would make them tradeable to other Conflux Network assets as well and open up even more opportunity to use HNT and FIL.
In addition to token swaps, there needs to be a way for IoT devices (and their respective infrastructure) to purchase storage and save data on Filecoin. That would be another step towards complete automation of decentralized internet and storage for IoT.
Filecoin Docs
PowerGate
- https://docs.textile.io/powergate/
- https://docs.textile.io/powergate/localnet/
- https://docs.textile.io/powergate/cli/pow/
- https://textileio.github.io/js-powergate-client/
Helium Network Endpoint