Conditions can take the shape of anything, be it the price of an asset, interest rates, etc.
- Send encrypted messages and token transfers using FairyRing and its inherent functionalities, leveraging aspects such as the
x/pepmodule. More specifically:- Create and sign transactions on Fairblock
- Encrypt transactions for deferred execution
- Retrieve transaction status and results
- Extract specific information from the decrypted messages using FairyRing. This information can be useful for creating your own specific apps leveraging this small sample of confidential computation possibilities.
Demo Quick Start
To run this demo, simply download this repo, and switch to this specific feature branch,feat-auction.
./bankMsgWithMemoAndDecryption.sh script, you will be prompted for the following basic inputs required to:
- Specify the recipient of said bank message,
- Encrypt the message with a target block height,
- Submit the encrypted transaction to the blockchain,
- Monitor the network for transaction processing, and show the decrypted result
Demo Details
The provided bash script,bankMsgWithMemoAndDecryption.sh, does the following:
| Step | Description |
|---|---|
| Takes User Input | Asks for a FairyRing recipient address, the amount of uFairy to transfer, the wallet account name sending funds, and a note for the transaction that acts as the message to be encrypted. |
| Gets Required Info | Fetches your public key, account address, account number, and sequence number from the list of devwallets available for the demo dev net. |
| Creates a Transaction | Generates an unsigned transaction with the specified details. |
| Signs the Transaction | Uses the specified account’s dev net credentials to sign it securely. |
Uses x/pep Module to Encrypt the Transaction | Uses the standard convention of encrypting a message. |
| Submits the Encrypted Transaction | Sends it to the local devnet. |
| Waits for Confirmation | Watches the local FairyRing devnet blockchain height and checks when your transaction is included. |
| Lists Decrypted Transactions | Once confirmed, it retrieves and displays the decrypted transaction. |
- Transaction details private using encryption.
- Ensures proper signing so transactions are valid.
- The script making it easy to interact with the FairyRing blockchain while keeping your transactions private!
Frequently Used CLI Commands
The output decrypted data is in JSON format. Developers are encouraged to parse the encrypted message for whatever data they may need for their own app design. This is where the true creative freedom comes into play! The following are CLI commands one can use within their own scripts to work with encrypted transactions at a rudimental level, including extracting information as needed. Expand the toggle to see its details. There are numerous ways to work with JSON files, we simply usejq within the following CLI commands shown and our demo script within this repo. See the official jq download docs here.
Commonly used CLI commands shown in this tutorial
Commonly used CLI commands shown in this tutorial
Fetch the Public Key for Encryption
- Use this in your app if you need to encrypt messages or transactions.
Getting a FairyRing Account Address
- Essential if you’re writing a wallet integration.
Create an Unsigned Transaction
- Builds a raw transaction JSON to be signed afterwards.
Get Account Number (for offline signing)
- Your application might need this if it manually constructs and signs transactions.
Get Sequence Number (Nonce)
- Obtaining the nonce is helpful when signing to prevent replay attacks.
Signs the Transaction Locally
- This allows offline signing, useful for hardware wallets or remote signing services.
Encrypting the Signed Transaction
Use the following to actually encrypt the transaction where one has to specify the target height, respective public key, and signed transaction.Submitting the Encrypted Transaction:
Use the below command to submit the encrypted transaction with a specified target height for decryption.Extracting the Transaction Hash (For Tracking)
Use the below command to extract the transaction hash that can be used to monitor the transaction status.Wait for Confirmation & Retrieves the Decrypted Transaction
This command monitors block height until the transaction is executed, and fetches decrypted transactions for further processing:- This can be used to display decrypted transaction details in your app.
How You Can Use These Commands in Your Own App
- Build your own app that uses the rudimentary encrypted transaction functionality with FairyRing.
- Automate transaction workflows → Utilize contract call-back, and thus fetch and process decrypted transactions once confirmed automatically.
- Build a transaction explorer → Extract TX hashes and track status.
Next Steps
Congratulations! You have now seen an example of encrypting a transaction with a message and transfer amount. There are several next steps you can take now anon.- Check out the actual time bomb demo app on the FairyRing testnet here.
- Check out our other quick starts to see how to build with other networks integrating into FairyRing in the Quick Start.
- Join our discord and discuss new build ideas! We host frequent developer hours to encourage more novel ideas with confidential computation.
general conditions instead of the default block height condition id used currently within FairyRing.
Encrypt transactions for x/pep module
This tutorial explains how to encrypt your transaction for the x/pep module using the encrypter built into fairyringd.
Ensure you have installed the fairyring binary before following the instructions below.
This section focuses on simple IBE-MPC encrypted transactions, using a target block height as the condition for automatic decryption and execution.
Encrypt your transaction
- Getting the public key for encryption
- Create the signed transaction. We’ll use a bank send transaction in this example.
[FROM_ADDRESS]is the address you are using to send the token.[TO_ADDRESS]is the recipient address.[AMOUNT]is the amount you would like to send.[YOUR_ACCOUNT_NAME]is the account name of your[FROM_ADDRESS].--gas-pricesis the gas price you are paying.--generate-onlymeans you only generate the unsigned transaction.-o jsonmeans to output the unsigned transaction injsonformat.> unsigned.jsonmeans outputs the unsigned transaction to a file namedunsigned.json.
100ufairy from alice (fairy18hl5c9xn5dze2g50uaw0l2mr02ew57zkynp0td) to fairy1qnk2n4nlkpw9xfqntladh74w6ujtulwnsgww3g.
The unsigned.json looks something like this:
- Signing the transaction
[ACCOUNT_NAME]replace all instances to the account name you are using to sign the transaction.--offlinemeans that you are signing your transaction offline with the provided account number & sequence instead of fetching it from the chain.--account-numberis your account number, the command above will fetch it for you automatically.--sequenceis the pep nonce of your address, the command above will fetch it for you automatically.
echo $SIGNED | jq
- Encrypting the transaction
[TARGET_HEIGHT / REQ-ID]is the target execution height of your transaction, or if you are encrypting a general tx, it is the request id / identity. It will also be used when you submit the encrypted transaction.$PUBKEYis the public key (encryption key) you got from Step 1.$SIGNEDis the signed transaction from Step 3.
- Check the encrypted transaction by:
echo $ENCRYPTED
- Submit the encrypted transaction
$ENCRYPTEDis the hex encoded encrypted tx fromencrypter[TARGET_HEIGHT]is the target execution height of your transaction. This should be the same as the[TARGET_HEIGHT]used when encrypting the transaction usingencrypter[ACCOUNT_NAME]is the account you would like to send the transaction from. This should be the same as the account you used to sign the transaction.
$ENCRYPTEDis the hex encoded encrypted tx fromencrypter[REQ-ID]is the request id / identity used in encryption. This should be the same as the[REQ-ID]used when encrypting the transaction usingencrypter[ACCOUNT_NAME]is the account you would like to send the transaction from. This should be the same as the account you used to sign the transaction.