Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 73 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ To add a wallet, you can do the following:

```sh
cargo run -- wallet create

```

This will prompt you for a a name and a password. Keep in mind that losing the
Expand All @@ -102,8 +101,80 @@ cargo run -- provider create

This will prompt you for a name, a kind (only UTxORPC supported), whether it is for mainnet or testnet, a URL and the possibility to add headers.

>>> If you have a [Demeter](https://demeter.run) port you would have to set the URL as `https://{host}` and on put `dmtr-api-key:YOUR_API_KEY` on the headers.
> If you have a [Demeter](https://demeter.run) port you would have to set the URL as `https://{host}` and on put `dmtr-api-key:YOUR_API_KEY` on the headers.

# Examples

In the `examples` folder you can find scripts demonstrating advanced capabilities.

## Batch transactions

This example shows how to send transactions to multiple recipients in a batch.

**Location:** `examples/batch-transactions/`

**Usage:**
```sh
./transfer.sh <sender_wallet> <receiver_wallets_list> <lovelace_amount>
```

**Arguments:**
- `sender_wallet`: Name of the wallet sending the funds (e.g., `alice`)
- `receiver_wallets_list`: Comma-separated list of recipient wallet names (e.g., `bob,charlie,mark`)
- `lovelace_amount`: Amount in lovelaces to send to each recipient (e.g., `1000000`)

**Example:**
```sh
./transfer.sh alice bob,charlie,mark 1000000
```

This will send 1,000,000 lovelaces from Alice's wallet to Bob, Charlie, and Mark individually.

## Scheduled tasks

This example demonstrates how to schedule recurring transactions using cron expressions.

**Location:** `examples/scheduled-tasks/`

**Usage:**
```sh
./transfer.sh <sender_wallet> <receiver_wallet> <lovelace_amount> <cron_string>
```

**Arguments:**
- `sender_wallet`: Name of the wallet sending the funds (e.g., `alice`)
- `receiver_wallet`: Name of the recipient wallet (e.g., `bob`)
- `lovelace_amount`: Amount in lovelaces to send (e.g., `1000000`)
- `cron_string`: Cron schedule expression in the format `'minute hour day month weekday'`

**Example:**
```sh
./transfer.sh alice bob 1000000 '0 */2 * * *'
```

This will schedule a transfer of 1,000,000 lovelaces from Alice to Bob every 2 hours.

## Complex transaction

This example shows how to interact with a protocol that requires several parameters, specifically creating a ship in [Asteria](https://asteria.txpipe.io).

**Location:** `examples/complex-transaction/`

**Usage:**
```sh
./create-ship.sh <player_wallet> <pos_x> <pos_y>
```

**Arguments:**
- `player_wallet`: Name of the player's wallet (e.g., `alice`)
- `pos_x`: X coordinate for the ship position (integer)
- `pos_y`: Y coordinate for the ship position (integer)

**Example:**
```sh
./create-ship.sh alice 25 25
```

This will create a new ship for Alice at coordinates (25, 25) in [Asteria](https://asteria.txpipe.io).

> Note: you need to use a provider with the Cardano preview testnet in order to submit this transaction
4 changes: 2 additions & 2 deletions dist-workspace.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ cargo-dist-version = "0.29.0"
# CI backends to support
ci = "github"
# The installers to generate for each app
installers = ["shell", "npm", "homebrew"]
installers = ["shell", "powershell", "npm", "homebrew"]
# A GitHub repo to push Homebrew formulas to
tap = "txpipe/homebrew-tap"
# Target platforms to build apps for (Rust target-triple syntax)
targets = ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"]
targets = ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"]
# Publish jobs to run in CI
publish-jobs = ["homebrew"]
# Which actions to run on pull requests
Expand Down
79 changes: 79 additions & 0 deletions docs/examples.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: Examples
sidebar:
order: 5
---

In the CShell [repo](https://github.com/txpipe/cshell) you can find scripts demonstrating advanced capabilities.

## Batch transactions

This example shows how to send transactions to multiple recipients in a batch.

**Location:** [`examples/batch-transactions/`](https://github.com/txpipe/cshell/tree/main/examples/batch-transactions)

**Usage:**
```sh
./transfer.sh <sender_wallet> <receiver_wallets_list> <lovelace_amount>
```

**Arguments:**
- `sender_wallet`: Name of the wallet sending the funds (e.g., `alice`)
- `receiver_wallets_list`: Comma-separated list of recipient wallet names (e.g., `bob,charlie,mark`)
- `lovelace_amount`: Amount in lovelaces to send to each recipient (e.g., `1000000`)

**Example:**
```sh
./transfer.sh alice bob,charlie,mark 1000000
```

This will send 1,000,000 lovelaces from Alice's wallet to Bob, Charlie, and Mark individually.

## Scheduled tasks

This example demonstrates how to schedule recurring transactions using cron expressions.

**Location:** [`examples/scheduled-tasks/`](https://github.com/txpipe/cshell/tree/main/examples/scheduled-tasks)

**Usage:**
```sh
./transfer.sh <sender_wallet> <receiver_wallet> <lovelace_amount> <cron_string>
```

**Arguments:**
- `sender_wallet`: Name of the wallet sending the funds (e.g., `alice`)
- `receiver_wallet`: Name of the recipient wallet (e.g., `bob`)
- `lovelace_amount`: Amount in lovelaces to send (e.g., `1000000`)
- `cron_string`: Cron schedule expression in the format `'minute hour day month weekday'`

**Example:**
```sh
./transfer.sh alice bob 1000000 '0 */2 * * *'
```

This will schedule a transfer of 1,000,000 lovelaces from Alice to Bob every 2 hours.

## Complex transaction

This example shows how to interact with a protocol that requires several parameters, specifically creating a ship in [Asteria](https://asteria.txpipe.io).

**Location:** [`examples/complex-transaction/`](https://github.com/txpipe/cshell/tree/main/examples/complex-transaction)

**Usage:**
```sh
./create-ship.sh <player_wallet> <pos_x> <pos_y>
```

**Arguments:**
- `player_wallet`: Name of the player's wallet (e.g., `alice`)
- `pos_x`: X coordinate for the ship position (integer)
- `pos_y`: Y coordinate for the ship position (integer)

**Example:**
```sh
./create-ship.sh alice 25 25
```

This will create a new ship for Alice at coordinates (25, 25) in [Asteria](https://asteria.txpipe.io).

> Note: you need to use a provider with the Cardano preview testnet in order to submit this transaction
7 changes: 7 additions & 0 deletions docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ In this guide we're going to learn how to go from zero to a running Cshell insta
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/txpipe/cshell/releases/latest/download/cshell-installer.sh | sh
```
</TabItem>
<TabItem label="windows">
You can use PowerShell to install Cshell on your system:

```sh
powershell -c "irm https://github.com/txpipe/cshell/releases/latest/download/cshell-installer.ps1 | iex"
```
</TabItem>
<TabItem label="npm">
You can use Npm to install Cshell on your system:

Expand Down
61 changes: 61 additions & 0 deletions examples/batch-transactions/transfer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# Validate arguments
if [ $# -ne 3 ]; then
echo "Error: exactly 3 arguments are required"
echo "Usage: $0 <sender_wallet> <receiver_wallets_list> <lovelace_amount>"
echo "Example: $0 alice bob,charlie,mark 1000000"
exit 1
fi

# Get arguments
SENDER_WALLET=$1
RECEIVER_WALLETS=$2
AMOUNT=$3

# Validate sender wallet name is not empty
if [ -z "$SENDER_WALLET" ]; then
echo "Error: sender wallet name cannot be empty"
exit 1
fi

# Validate receiver wallets list is not empty
if [ -z "$RECEIVER_WALLETS" ]; then
echo "Error: receiver wallets list cannot be empty"
exit 1
fi

# Validate amount is a positive integer
if ! [[ "$AMOUNT" =~ ^[0-9]+$ ]]; then
echo "Error: amount must be a positive integer"
exit 1
fi

# Get sender wallet info
SENDER_INFO=$(cshell wallet info --name $SENDER_WALLET 2>&1)
if [ $? -ne 0 ]; then
echo "Error: sender wallet '$SENDER_WALLET' does not exist"
exit 1
fi

SENDER_ADDRESS=$(echo "$SENDER_INFO" | grep "Address (testnet)" | awk '{print $5}')

for RECEIVER_WALLET in ${RECEIVER_WALLETS//,/ }; do

echo "Sending $AMOUNT lovelaces from $SENDER_WALLET to $RECEIVER_WALLET"

RECEIVER_INFO=$(cshell wallet info --name $RECEIVER_WALLET 2>&1)
if [ $? -ne 0 ]; then
echo "Error: receiver wallet '$RECEIVER_WALLET' does not exist"
exit 1
fi

RECEIVER_ADDRESS=$(echo "$RECEIVER_INFO" | grep "Address (testnet)" | awk '{print $5}')

cshell tx invoke \
--tx3-file ./transfer.tx3 --signers $SENDER_WALLET --unsafe \
--tx3-args-json "{\"sender\":\"$SENDER_ADDRESS\",\"receiver\":\"$RECEIVER_ADDRESS\",\"quantity\":$AMOUNT}"

echo ""

done
22 changes: 22 additions & 0 deletions examples/batch-transactions/transfer.tx3
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
party Sender;

party Receiver;

tx transfer(
quantity: Int
) {
input source {
from: Sender,
min_amount: Ada(quantity) + fees,
}

output {
to: Receiver,
amount: Ada(quantity),
}

output {
to: Sender,
amount: source - Ada(quantity) - fees,
}
}
Loading
Loading