Skip to content

Commit fea6270

Browse files
Copilot0xrinegade
andcommitted
Add comprehensive C++ SDK docs and tutorials to website with examples
Co-authored-by: 0xrinegade <[email protected]>
1 parent 6b087cd commit fea6270

File tree

12 files changed

+1328
-2
lines changed

12 files changed

+1328
-2
lines changed

examples/README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# SVM-Pay Examples
2+
3+
This directory contains comprehensive examples demonstrating SVM-Pay integration across different languages, frameworks, and use cases.
4+
5+
## Examples by Language/Platform
6+
7+
### JavaScript/TypeScript Examples
8+
9+
- **[web-payment-demo.jsx](./web-payment-demo.jsx)** - Basic web payment integration with React
10+
- **[point-of-sale-demo.tsx](./point-of-sale-demo.tsx)** - Point-of-sale terminal implementation
11+
- **[subscription-payment-demo.tsx](./subscription-payment-demo.tsx)** - Subscription payment processing
12+
- **[cross-chain-payment-demo.html](./cross-chain-payment-demo.html)** - Cross-chain payment flows
13+
- **[wallet-connect-demo.html](./wallet-connect-demo.html)** - WalletConnect integration
14+
- **[wallet-connect-test.tsx](./wallet-connect-test.tsx)** - WalletConnect testing utilities
15+
16+
### C++ SDK Examples
17+
18+
- **[cpp-examples/](./cpp-examples/)** - Complete C++ SDK examples
19+
- **[basic-payment/](./cpp-examples/basic-payment/)** - Simple payment URL creation and processing
20+
- **[url-parsing/](./cpp-examples/url-parsing/)** - URL parsing and validation examples
21+
- **[network-adapters/](./cpp-examples/network-adapters/)** - Working with different network adapters
22+
23+
### Assembly-BPF Examples
24+
25+
- **[assembly-bpf/](./assembly-bpf/)** - Low-level BPF program examples
26+
- Payment processor programs
27+
- Cross-chain bridge implementations
28+
- Custom middleware and validation programs
29+
30+
### Integration Examples
31+
32+
- **[n8n-integration/](./n8n-integration/)** - Workflow automation with n8n
33+
- Payment workflow nodes
34+
- Automated payment processing
35+
- Integration templates
36+
37+
## Getting Started
38+
39+
### Prerequisites
40+
41+
**For JavaScript/TypeScript examples:**
42+
```bash
43+
npm install svm-pay
44+
```
45+
46+
**For C++ examples:**
47+
```bash
48+
# Install dependencies (Ubuntu/Debian)
49+
sudo apt-get install build-essential cmake libcurl4-openssl-dev libssl-dev
50+
51+
# Build and install C++ SDK
52+
cd ../cpp-sdk
53+
mkdir build && cd build
54+
cmake ..
55+
make install
56+
```
57+
58+
**For Assembly-BPF examples:**
59+
```bash
60+
npm install svm-pay
61+
# Assembly-BPF SDK is included with the main package
62+
```
63+
64+
### Running Examples
65+
66+
**Web examples:**
67+
Most HTML examples can be opened directly in a browser or served with a local HTTP server:
68+
```bash
69+
# Using Python
70+
python -m http.server 8000
71+
72+
# Using Node.js
73+
npx serve .
74+
```
75+
76+
**React/TypeScript examples:**
77+
```bash
78+
# Copy example code into your React project
79+
# Or use the examples as templates for new components
80+
```
81+
82+
**C++ examples:**
83+
```bash
84+
cd cpp-examples
85+
mkdir build && cd build
86+
cmake ..
87+
make
88+
89+
# Run individual examples
90+
./basic-payment/basic_payment
91+
./url-parsing/url_parsing
92+
./network-adapters/network_adapter
93+
```
94+
95+
## Example Categories
96+
97+
### Basic Payment Processing
98+
- Simple transfers
99+
- SPL token payments
100+
- Payment URL creation and parsing
101+
- Transaction validation
102+
103+
### Advanced Features
104+
- Cross-chain payments
105+
- Network adapter usage
106+
- Asynchronous operations
107+
- Error handling patterns
108+
109+
### Real-World Applications
110+
- E-commerce integration
111+
- Point-of-sale systems
112+
- Subscription billing
113+
- Multi-network support
114+
115+
### Integration Patterns
116+
- React components
117+
- Vue.js integration
118+
- Angular services
119+
- Server-side processing
120+
- Mobile applications
121+
122+
## Documentation
123+
124+
For detailed documentation and tutorials:
125+
- [Main Documentation](../docs/)
126+
- [C++ SDK Documentation](../cpp-sdk/README.md)
127+
- [Assembly-BPF SDK](../docs/assembly-bpf/)
128+
- [Developer Guide](../docs/developer-guide.md)
129+
130+
## Contributing
131+
132+
To contribute new examples:
133+
1. Follow the existing example structure
134+
2. Include comprehensive README files
135+
3. Add appropriate comments and documentation
136+
4. Test across different environments
137+
5. Submit a pull request
138+
139+
## Support
140+
141+
For questions about examples or integration:
142+
- Check the [documentation](../docs/)
143+
- Review existing examples for patterns
144+
- Open an issue for specific problems
145+
- Join our community discussions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
# Example sources
4+
set(EXAMPLE_SOURCES
5+
basic_payment.cpp
6+
url_parsing.cpp
7+
network_adapter.cpp
8+
)
9+
10+
# Create example executables
11+
foreach(EXAMPLE_SOURCE ${EXAMPLE_SOURCES})
12+
get_filename_component(EXAMPLE_NAME ${EXAMPLE_SOURCE} NAME_WE)
13+
add_executable(${EXAMPLE_NAME} ${EXAMPLE_SOURCE})
14+
target_link_libraries(${EXAMPLE_NAME} svm-pay)
15+
set(EXAMPLE_TARGETS ${EXAMPLE_TARGETS} ${EXAMPLE_NAME})
16+
endforeach()
17+
18+
# Install examples
19+
install(TARGETS ${EXAMPLE_TARGETS}
20+
DESTINATION bin/examples
21+
)

examples/cpp-examples/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# C++ SDK Examples
2+
3+
This directory contains C++ examples demonstrating SVM-Pay integration.
4+
5+
## Examples
6+
7+
- **basic-payment/** - Simple payment URL creation and processing
8+
- **url-parsing/** - URL parsing and validation examples
9+
- **network-adapters/** - Working with different network adapters
10+
- **async-operations/** - Asynchronous network operations
11+
- **cross-platform/** - Cross-platform development examples
12+
13+
## Building Examples
14+
15+
All examples can be built using CMake:
16+
17+
```bash
18+
cd cpp-examples
19+
mkdir build && cd build
20+
cmake ..
21+
make
22+
23+
# Run examples
24+
./basic-payment/basic_payment
25+
./url-parsing/url_parsing
26+
./network-adapters/network_adapter
27+
```
28+
29+
## Prerequisites
30+
31+
- C++17 compatible compiler
32+
- CMake 3.16 or higher
33+
- SVM-Pay C++ SDK installed
34+
- cURL and OpenSSL libraries
35+
36+
## Integration
37+
38+
To use these examples in your own projects, copy the relevant code and ensure you have the SVM-Pay C++ SDK properly installed and linked.
39+
40+
For more information, see the [C++ SDK documentation](/docs/cpp-sdk) and [tutorials](/tutorials/cpp-sdk).
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Basic Payment Example
2+
3+
This example demonstrates how to create simple payment URLs and process basic transactions using the SVM-Pay C++ SDK.
4+
5+
## Features Demonstrated
6+
7+
- SDK initialization
8+
- Creating transfer URLs with metadata (label, message, memo)
9+
- Generating secure reference IDs
10+
- Basic error handling
11+
12+
## Building
13+
14+
```bash
15+
cd basic-payment
16+
g++ -std=c++17 basic_payment.cpp -lsvm-pay -lcurl -lssl -lcrypto -o basic_payment
17+
./basic_payment
18+
```
19+
20+
## Code Overview
21+
22+
The example shows:
23+
1. Initializing the SVM-Pay SDK
24+
2. Creating a client for Solana network
25+
3. Creating a payment URL with recipient, amount, and metadata
26+
4. Generating a reference ID for transaction tracking
27+
5. Parsing and displaying the created URL
28+
29+
## Next Steps
30+
31+
- Try the [URL Parsing Example](../url-parsing/) to learn about parsing payment URLs
32+
- See the [Network Adapters Example](../network-adapters/) for working with different blockchains
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#include <iostream>
2+
#include <svm-pay/svm_pay.hpp>
3+
4+
using namespace svm_pay;
5+
6+
int main() {
7+
std::cout << "SVM-Pay C++ SDK - Basic Payment Example\n";
8+
std::cout << "========================================\n\n";
9+
10+
try {
11+
// Initialize the SDK
12+
initialize_sdk();
13+
14+
// Create a client
15+
Client client(SVMNetwork::SOLANA);
16+
17+
std::cout << "1. Creating a transfer URL...\n";
18+
19+
// Create a simple transfer URL
20+
std::string recipient = "7v91N7iZ9eyTktBwWC2ckrjdLhvmS4R1HqvYZzG5FGvn";
21+
std::string amount = "1.5";
22+
23+
std::unordered_map<std::string, std::string> options = {
24+
{"label", "Coffee Shop"},
25+
{"message", "Payment for coffee and pastry"},
26+
{"memo", "Order #12345"}
27+
};
28+
29+
std::string payment_url = client.create_transfer_url(recipient, amount, options);
30+
std::cout << " Payment URL: " << payment_url << "\n\n";
31+
32+
std::cout << "2. Parsing the payment URL...\n";
33+
34+
// Parse the URL back
35+
auto request = client.parse_url(payment_url);
36+
37+
std::cout << " Request type: " << request_type_to_string(request->type) << "\n";
38+
std::cout << " Network: " << network_to_string(request->network) << "\n";
39+
std::cout << " Recipient: " << request->recipient << "\n";
40+
41+
if (request->label.has_value()) {
42+
std::cout << " Label: " << request->label.value() << "\n";
43+
}
44+
45+
if (request->message.has_value()) {
46+
std::cout << " Message: " << request->message.value() << "\n";
47+
}
48+
49+
if (request->memo.has_value()) {
50+
std::cout << " Memo: " << request->memo.value() << "\n";
51+
}
52+
53+
// Cast to TransferRequest to access amount
54+
if (request->type == RequestType::TRANSFER) {
55+
auto transfer_request = dynamic_cast<TransferRequest*>(request.get());
56+
if (transfer_request) {
57+
std::cout << " Amount: " << transfer_request->amount << "\n";
58+
}
59+
}
60+
61+
std::cout << "\n3. Generating reference IDs...\n";
62+
63+
// Generate reference IDs
64+
for (int i = 0; i < 3; ++i) {
65+
std::string ref = client.generate_reference();
66+
std::cout << " Reference " << (i + 1) << ": " << ref << "\n";
67+
}
68+
69+
std::cout << "\n4. Creating a transaction URL...\n";
70+
71+
// Create a transaction URL
72+
std::string transaction_link = "https://api.example.com/transaction";
73+
std::unordered_map<std::string, std::string> tx_options = {
74+
{"label", "NFT Marketplace"},
75+
{"message", "Purchase NFT #42"}
76+
};
77+
78+
std::string transaction_url = client.create_transaction_url(recipient, transaction_link, tx_options);
79+
std::cout << " Transaction URL: " << transaction_url << "\n\n";
80+
81+
std::cout << "5. Working with different networks...\n";
82+
83+
// Create URLs for different networks
84+
std::vector<SVMNetwork> networks = {SVMNetwork::SOLANA, SVMNetwork::SONIC, SVMNetwork::ECLIPSE, SVMNetwork::SOON};
85+
86+
for (auto network : networks) {
87+
std::unordered_map<std::string, std::string> net_options = {
88+
{"network", network_to_string(network)}
89+
};
90+
91+
std::string url = client.create_transfer_url(recipient, "2.0", net_options);
92+
std::cout << " " << network_to_string(network) << ": " << url << "\n";
93+
}
94+
95+
std::cout << "\nExample completed successfully!\n";
96+
97+
// Cleanup
98+
cleanup_sdk();
99+
100+
} catch (const std::exception& e) {
101+
std::cerr << "Error: " << e.what() << std::endl;
102+
return 1;
103+
}
104+
105+
return 0;
106+
}

0 commit comments

Comments
 (0)