Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
98 changes: 98 additions & 0 deletions DevnetSponsoredTx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Concordium Sponsored Transactions Demo

Demo for sponsored transactions on Concordium. Users transfer PLT tokens without paying gas fees - a sponsor wallet covers the cost.

## Project Structure

```
DevnetSponsoredTx/
├── docker-compose.yml # Orchestrates frontend and backend containers
├── frontend/
│ ├── Dockerfile # Multi-stage build, serves with runtime config injection
│ ├── build-and-serve.sh # Injects env vars into index.html at container startup
│ ├── src/
│ │ └── constants.ts # Runtime config from window.runtimeConfig
│ └── index.html # Contains placeholders for runtime injection
└── backend/
├── Dockerfile # Node.js backend build
└── wallet/ # Sponsor wallet export file (gitignored)
```

## Docker

Create a `.env` file in the project root or set default values or secrets in the docker-compose:
```env
CONCORDIUM_GRPC_HOST=your-grpc-host
CCDSCAN_URL=your-ccdscan-url
```

Add your sponsor wallet export file to `backend/wallet/sponsor.export`, then:

```bash
docker compose up --build
```

Open http://localhost:3000 and connect your Browser Wallet.

### Environment Variables

Frontend (runtime injection via `build-and-serve.sh`):
- `BACKEND_URL` - Backend API URL (default: `http://localhost:3002`)
- `TOKEN_ID` - Token identifier (default: `EURtest`)
- `TOKEN_DECIMALS` - Token decimals (default: `6`)
- `CCDSCAN_URL` - CCDScan URL for transaction links (required)

Backend:
- `CONCORDIUM_GRPC_HOST` - Concordium node host (required)
- `CONCORDIUM_GRPC_PORT` - Concordium node port (default: `20000`)
- `CONCORDIUM_USE_SSL` - Use SSL for gRPC connection (default: `true`)
- `SPONSOR_WALLET_PATH` - Path to sponsor wallet export file
- `PORT` - Backend port (default: `3002`)

## Local Development

### Backend

```bash
cd backend
npm install
```

Create `backend/.env`:
```env
CONCORDIUM_GRPC_HOST=your-grpc-host
CONCORDIUM_GRPC_PORT=20000
CONCORDIUM_USE_SSL=true
SPONSOR_WALLET_PATH=./wallet/sponsor.export
PORT=3002
```

Add your sponsor wallet export file to `backend/wallet/sponsor.export`, then:

```bash
npm run start:dev
```

### Frontend

```bash
cd frontend
npm install
npm run build
npm run start
```

Open http://localhost:5173 and connect your Browser Wallet.

## How It Works

1. User connects Browser Wallet
2. User enters recipient and amount
3. Backend creates the transaction and signs it with the sponsor key
4. User signs to authorize the token transfer
5. Sponsor wallet pays the gas fees

## Notes

- Sponsor wallet needs CCD to cover gas fees
- Wallet export files in `backend/wallet/` are gitignored
5 changes: 5 additions & 0 deletions DevnetSponsoredTx/backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
.env
.env.*
wallet/*.export
15 changes: 15 additions & 0 deletions DevnetSponsoredTx/backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Concordium Node Configuration
CONCORDIUM_GRPC_HOST=grpc.testnet.concordium.com
CONCORDIUM_GRPC_PORT=20000
CONCORDIUM_USE_SSL=true

# Token Configuration
DEFAULT_TOKEN_ID=YOUR_TOKEN_ID
TOKEN_DECIMALS=6

# Sponsor Wallet
SPONSOR_WALLET_PATH=./wallet/sponsor.export

# Server Configuration
PORT=3002
NODE_ENV=development
8 changes: 8 additions & 0 deletions DevnetSponsoredTx/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
dist/
.env
wallet/*.export
wallet/*.json
*.log
.DS_Store
*.tsbuildinfo
13 changes: 13 additions & 0 deletions DevnetSponsoredTx/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20-alpine

WORKDIR /app

COPY package*.json ./
RUN npm install --legacy-peer-deps

COPY . .
RUN rm -rf dist && npx tsc --incremental false

EXPOSE 3002

CMD ["npm", "run", "start:prod"]
Loading
Loading