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


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).


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.


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.


  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.


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...
Rust libp2p and tokio demo

Rust libp2p and tokio demo This repository contains code to show basic usage of the async programming using tokio and p2p - libp2p library in Rust. Th

A very bare-bone Block Chain demo that purely implemented by Rust and yew
A very bare-bone Block Chain demo that purely implemented by Rust and yew

Intro bloc is one of bare-bone blockchain demo written by Rust, Yew during my learning BlockChain, about years ago. see demo here It just demonstrate

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

Substrate NFT !ink smart contract base

Substrate !ink NFT simple implementation This is a simple working version of base NFT smart contract written using latest (as of this date) !ink 3.0.0

Christopher Fok
Christopher Fok
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
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 Install Solana from

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

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

Solana Foundation 9.7k Dec 3, 2022
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 Nov 28, 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 638 Nov 23, 2022
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.

Blue Terra 1 Jan 31, 2022
Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana (WIP) ⛏👷🚧⚠️

Solana BPF Boilerplate Simple template for building smart contract(Rust) and RPC Client(web3.js) on Solana This boilerplate provides the following. Si

ono 6 Jan 30, 2022
Heimdall is an advanced Ethereum smart contract toolkit for forensic and heuristic analysis.

Heimdall is an advanced EVM toolkit which aims to make dealing with smart contracts on EVM based chains easier. Installation & Usage Heimdall's update

Jonathan Becker 426 Nov 24, 2022