Skip to main content

Deposit and withdraw

In this tutorial, you will learn how to deposit additional funds in a job to extend its running time as well as withdraw excess funds from a job to reduce its running time.

Create a docker compose file

Create a file named docker-compose.yml describing the service being deployed:

cat > docker-compose.yml <<EOF
services:
echo-server:
image: marlinorg/oyster-cvm-tutorials-echo-server
network_mode: host
restart: unless-stopped
EOF

Deploy an enclave

Deploy an enclave using:

# Replace <key> with private key of the wallet
oyster-cvm deploy --wallet-private-key <key> --duration-in-minutes 15 --docker-compose docker-compose.yml

Make a note of the job id from the logs.

Use the list command to get the remaining time:

# Replace <address> with your wallet address
oyster-cvm list --address <address>

Deposit funds

Run

# Replace <key> with private key of the wallet
# Replace <job_id> with job id of the deployed enclave
oyster-cvm deposit --wallet-private-key <key> --job-id <job_id> --amount 20000

to deposit additional funds into the job. Note that the amount is passed assuming 6 decimals, therefore the above amount corresponds to 0.02 USDC.

Use the list command to get the remaining time again:

# Replace <address> with your wallet address
oyster-cvm list --address <address>

Do you see any changes?

Withdraw funds

Run

# Replace <key> with private key of the wallet
# Replace <job_id> with job id of the deployed enclave
oyster-cvm withdraw --wallet-private-key <key> --job-id <job_id> --amount 10000

to withdraw some funds from the job. As before, the amount is passed assuming 6 decimals, therefore the above amount corresponds to 0.01 USDC.

Use the list command to get the remaining time again:

# Replace <address> with your wallet address
oyster-cvm list --address <address>

Do you see any changes?

Something important to note is the "Required buffer" amount in the logs. You can only withdraw funds when the job would have at least this amount remaining in it after the withdrawal. As an exercise, try withdrawing amounts greater than what would be allowed :)