Demo: Connect Phala's Fat Contract to external storage services, both centralized (Amazon s3) and decentralized .

Overview

This demo shows how to connect Phala's Fat Contract to external storage services, both centralized (Amazon s3) and decentralized (Arweave/Filecoin through 4everland, Storj, Filebase).

Background

In order to build Web3 programs, Phala Network provides the web3 computing power and any storage services (web2 or web3) with a RESTful API provides the data storage. To do this, we can use the native HTTP request support in Fat Contract to connect them.

Setup

The demo shows the GET and PUT request for the Amazon S3 API. The same authentication and request process can be applied to other services like 4everland, Storj, and Filebase, since the S3 API has become the industrial standard for storage interfaces. The only change then is to specify the correct host in the HTTP request (and correspondingly in the signing process), and use the correct S3 API credentials.

You need to first create an account and set up a bucket on your selected storage interface, then obtain the S3 API credentials, i.e. 1) access key and 2) secret key, to seal in the contract. All interfaces have free tiers for trial.

A bucket is a container for data objects. For Amazon S3, you can have up to 100 buckets but can store any number objects in a bucket. The key of the object is unqiue within the bucket. For a more detailed overview, check here

NOTE: For Amazon S3, you also need to select a region. Generally, a region closest to your location is preferred. For others, the default region should be set to be us-east-1.

Details

  1. The demo safely seals the API credentials in the contract storage, thanks to the privacy-protecting Phala Blockchain that encrypts transactions and states by default.
  2. For all the above storage services, the AWS4 signature added to the authorization header in the HTTP request is manually assembled. You can check the general signing process and the specific signing requirements for 3.

NOTE: Although a Rust SDK for aws is in development , the ink! contract does not support the async functions that most API SDKs use in awaiting HTTP responses.

  1. The demo encrypts and decrypts the data to be stored before uploading and downloading from the storage service, using RustCrypto’s AEAD crate. You can customize the process (e.g. algorithm, choice of key/nonce) by referencing here.

Performance

Since the GET and PUT logic is written in a Query (a function that does not alter the contract storage with an immutable reference in the function parameter), their execution is sent to a Phala Secure Worker using the secure enclave.

This means the HTTP request is made in a fully-functional off-chain execution environment. As such, its performance is the same as any client-server programs.

  • Maximum object size for a single PUT operation: 5GB
  • Maximum object size for a multi-part PUT operation: 5TB
  • Maximum object size for a single GET operation: 5TB

For details of other API action limits, you can check for Amazon S3 and for 4everland.

You might also like...
Blue Terra is a decentralized protocol for the global democratization of stable and accessible property rights.
Blue Terra is a decentralized protocol for the global democratization of stable and accessible property rights.

🏝️ The official Blue Terra KYC program. Blue Terra holders interact with this program to activate the leases embedded in their NFTs.

Kryptokrona SDK in Rust for building decentralized private communication and payment systems.

Kryptokrona Rust SDK Kryptokrona is a decentralized blockchain from the Nordic based on CryptoNote, which forms the basis for Monero, among others. Cr

An infrastructure for peer-to-peer, decentralized, and collaborative software.

karyon An infrastructure for peer-to-peer, decentralized, and collaborative software. In molecular biology, a Karyon is essentially "a part of the cel

Microunit is a decentralized unit orchestration framework.

Microunit is a decentralized unit orchestration framework.

cashio is a decentralized stablecoin made for the people, by the people.
cashio is a decentralized stablecoin made for the people, by the people.

cashio is a decentralized stablecoin made for the people, by the people. We're in active development. For the latest updates, please join our c

Subsocial full node with Substrate/Polkadot pallets for decentralized communities: blogs, posts, comments, likes, reputation.

Subsocial Node by DappForce Subsocial is a set of Substrate pallets with web UI that allows anyone to launch their own decentralized censorship-resist

Polkadex - An Orderbook-based Decentralized Exchange using the Substrate Blockchain Framework.

What is Polkadex? 🚀 Polkadex is a Open Source, Decentralized Exchange Platform made using Substrate Blockchain Framework that provides traders with t

Summer Boot (web2&web3, the decentralized web framework)

Summer Boot The next generation decentralized web framework allows users to manage and share their own data. It will be a wide area and cross regional

Decentralized stablecoin on Juno Network.

⚡️ C O S M W A S M S T A B L E C O I N ⚡️ coming soon to junø network 💡 Overview Ultra is a CosmWasm stablecoin protocol developed on JunoNetwork by

Owner
Christopher Fok
Christopher Fok
Dank - The Internet Computer Decentralized Bank - A collection of Open Internet Services - Including the Cycles Token (XTC)

Dank - The Internet Computer Decentralized Bank Dank is a collection of Open Internet Services for users and developers on the Internet Computer. In t

Psychedelic 56 Nov 12, 2022
RGB20 Contract Demo based on RGB v0.11.0-beta.6

RGB20 Demo based on RGB v0.11 Pre-request To complete the demo, you need to set up the following toolchains: Git Rust RGB-CLI Bitcoin Local Env RGB-CL

null 18 Jul 9, 2024
Temporary edit external crates that your project depends on

rhack You want to quickly put a sneaky macro kind of like dbg! into external crates to find out how some internal data structure works? If so rhack is

Ryo Nakao 119 Nov 3, 2022
An intentionally-limited Rust implementation of the Docker runtime with no external dependencies.

lil-docker An lightweight Rust implementation of Docker's run command. lil docker is an accessible implementation of a very basic Docker runner (which

Miguel Piedrafita 38 Jan 9, 2023
egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native

?? egui: an easy-to-use GUI in pure Rust ?? Click to run the web demo ?? egui is a simple, fast, and highly portable immediate mode GUI library for Ru

Cronus Diamond 7 Aug 13, 2022
A program on solana blockchain to provide escrow services.

Environment Setup Install Rust from https://rustup.rs/ Install Solana from https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-to

null 0 Dec 24, 2021
Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.

Building 1. Install rustc, cargo and rustfmt. $ curl https://sh.rustup.rs -sSf | sh $ source $HOME/.cargo/env $ rustup component add rustfmt When buil

Solana Foundation 9.8k Jan 3, 2023
The Decentralized and Scaled Blockchain

Massa: The Decentralized and Scaled Blockchain Massa is a truly decentralized blockchain controlled by thousands of people. With the breakthrough mult

null 1.2k Dec 31, 2022
Open source Rust implementation of the Witnet decentralized oracle protocol, including full node and wallet backend 👁️🦀

witnet-rust is an open source implementation of the Witnet Decentralized Oracle Network protocol written in Rust. Components witnet-rust implements ma

The Witnet Project 155 Nov 21, 2022
Nym provides strong network-level privacy against sophisticated end-to-end attackers, and anonymous transactions using blinded, re-randomizable, decentralized credentials.

The Nym Privacy Platform The platform is composed of multiple Rust crates. Top-level executable binary crates include: nym-mixnode - shuffles Sphinx p

Nym 653 Dec 26, 2022