Phat Contract is a Rust-based contract that allows you to interact with an S3 bucket using HTTP requests. This contract provides methods to perform GET
, PUT
, DELETE
, and HEAD
operations on an S3 bucket.
Please note that the
endpoint
URL must not includehttps://
. For example, useendpoint.4everland.co
instead ofhttps://endpoint.4everland.co
for theendpoint
parameter.
- Set admin for the contract
- Seal S3 bucket access and secret keys
- Perform
PUT
,HEAD
,GET
, andDELETE
operations on an S3 bucket - Test the contract with a predefined S3 bucket and object
- rustc
1.69.0
- cargo-contract
3.0.1
or greater
Clone the repository and navigate to the directory:
git clone git@github.com:HashWarlock/PhatStorage.git
cd PhatStorage
Build the contract:
cargo contract build
Best way to interact with the contract is to load in https://phat.phala.network. You will:
- Upload the compiled
phat_storage.contract
file to the Phala blockchain - Instantiate your Phat Contract
- Activate your Phat Contract by adding staked PHA
Your dashboard will then look like as follows:
Set a new admin for the contract with the set_admin
function. Only the current admin can perform this operation.
Seal the S3 Bucket access and secret keys with the seal_keys
function. Only the admin can perform this operation.
Perform PUT
, HEAD
, GET
, and DELETE
operations on an S3 bucket with the s3_put
, s3_head
, s3_get
, and s3_delete
functions respectively. Only the admin can perform these operations and the keys must be configured.
Let's go through a user journey.
Test the contract with a predefined S3 bucket and object with the it_works
function. In the Phat UI, you can click the
Note: you will need to update the function to hardcode values to function correctly. If you have installed
swanky phala
and are running on a machine with x86 chip, you can execute the following:
swanky phala contract test -t phat_storage_bkup
The contract can return the following errors:
NoPermissions
: The caller is not the adminInvalidRequest
: The S3 operation failedKeysNotConfigured
: The access and secret keys are not configured