- Install DFINITY SDK using the following command:
DFX_VERSION=0.22.0 sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"- Add DFINITY to your PATH variables by appending the following line to your
.bashrc:
echo 'export PATH="$PATH:$HOME/bin"' >> "$HOME/.bashrc"- Start the DFINITY local environment in the background:
dfx start --background- Install project dependencies:
npm install- Make the deployment script executable:
chmod +x ./deploy.sh- Run the deployment script to build, deploy, and initialize canisters:
./deploy.sh --service-id '<YOUR_PRINCIPLE_HERE>'Note: This process may take some time.
-
getStatus- Description: Retrieves the current status of the canister, including memory and cycles usage.
- Returns: A
CanisterStatusResultcontaining the status or an error.
-
initializeCanister- Description: Initializes the canister with an authorized service ID. Only the controller can execute this.
- Parameters:
serviceId(Principal) – The identifier of the service.
- Returns: A
ServiceResultwith the service data or an error.
-
loadCanisterCode- Description: Loads Wasm code into the canister for deploying new canisters.
- Parameters:
blobData(Uint8Array) – The binary data of the Wasm code.
- Returns: A
BoolResultindicating success or error.
-
uploadFile- Description: Manages the upload of a file to a user's storage canister.
- Parameters:
file(FilePayload) – The file data to upload.userId(Text) – Identifier of the user uploading the file.isChunked(Bool) – Indicates if the file is being uploaded in chunks.
- Returns: A
FileResultwith file information or an error.
-
getFile- Description: Retrieves a specific chunk of a file from a user's storage canister.
- Parameters:
userId(Text) – Identifier of the user.fileId(Text) – Identifier of the file.canisterId(Text) – ID of the target storage canister.chunkNumber(Nat) – The chunk number to retrieve.
- Returns: A
FileChunkResultcontaining the file chunk or an error.
-
uploadFile- Description: Handles file uploads to the storage canister. Supports both full-file and chunked uploads.
- Parameters:
file(FilePayload) – File metadata and content.isChunked(Bool) – Whether the file is uploaded in chunks.
- Returns: A
BoolResultindicating success or failure.
-
getFile- Description: Retrieves a chunk of a file by its ID.
- Parameters:
fileId(Text) – The file's unique identifier.chunkNumber(Nat) – The chunk number to retrieve.
- Returns: A
FileChunkResultwith the file chunk and metadata or an error.
-
findOrCreateCanister- Description: Finds an existing canister with enough storage or deploys a new one for the user.
- Parameters:
userId(Text) – The user for whom the canister is being found/created.fileSize(bigint) – The size of the file to upload.
- Returns: A
Principalof the canister ornullif none are available.
-
deployCanister- Description: Deploys a new storage canister using the stored Wasm code.
- Returns: The
Principalof the newly deployed canister or throws an error.
-
findCanisterWithFreeSpace- Description: Searches a user's existing canisters for one with sufficient storage space.
- Parameters:
user(User) – The user object with canister references.fileSize(bigint) – The size of the file to upload.
- Returns: A
Principalof a canister with available storage or deploys a new one.