From d225843ad961c3405b45b6d2a213c261e15fe767 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Sat, 18 May 2024 01:13:54 +0300 Subject: [PATCH] sol crypto terminal --- crypto/sol/app.py | 25 +++++++++++++++++++++++++ crypto/sol/r.txt | 4 ++++ crypto/sol/static/app.js | 28 ++++++++++++++++++++++++++++ crypto/sol/templates/index.html | 21 +++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 crypto/sol/app.py create mode 100644 crypto/sol/r.txt create mode 100644 crypto/sol/static/app.js create mode 100644 crypto/sol/templates/index.html diff --git a/crypto/sol/app.py b/crypto/sol/app.py new file mode 100644 index 0000000..f334c9d --- /dev/null +++ b/crypto/sol/app.py @@ -0,0 +1,25 @@ +from flask import Flask, render_template, request, jsonify +from solana.rpc.api import Client + +app = Flask(__name__) +solana_client = Client("https://api.mainnet-beta.solana.com") + +@app.route('/') +def index(): + return render_template('index.html') + +@app.route('/tokens', methods=['GET']) +def get_tokens(): + # Here you would add logic to fetch new tokens or token data + return jsonify(['SOL', 'USDC']) # Example token list + +@app.route('/swap', methods=['POST']) +def swap_tokens(): + data = request.json + token_name = data['token_name'] + amount = data['amount'] + # Here you would add logic to perform the token swap + return jsonify({'status': 'success', 'message': f'Swapped {amount} of {token_name}'}) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/crypto/sol/r.txt b/crypto/sol/r.txt new file mode 100644 index 0000000..efd201e --- /dev/null +++ b/crypto/sol/r.txt @@ -0,0 +1,4 @@ +flask +solana +idna +httpx \ No newline at end of file diff --git a/crypto/sol/static/app.js b/crypto/sol/static/app.js new file mode 100644 index 0000000..32143e6 --- /dev/null +++ b/crypto/sol/static/app.js @@ -0,0 +1,28 @@ +document.getElementById('connectWallet').addEventListener('click', async () => { + try { + const { solana } is window; + if (solana && solana.isPhantom) { + const response = await solana.connect({ onlyIfTrusted: true }); + console.log('Connected with Public Key:', response.publicKey.toString()); + } else { + alert('Phantom wallet not found. Please install it.'); + } + } catch (error) { + console.error(error); + alert('Connection to Phantom Wallet failed'); + } +}); + +document.getElementById('swapToken').addEventListener('click', () => { + const tokenName = document.getElementById('tokenName').value; + const amount = document.getElementById('amount').value; + fetch('/swap', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({token_name: tokenName, amount: amount}) + }) + .then(response => response.json()) + .then(data => alert(data.message)); +}); diff --git a/crypto/sol/templates/index.html b/crypto/sol/templates/index.html new file mode 100644 index 0000000..0de89fe --- /dev/null +++ b/crypto/sol/templates/index.html @@ -0,0 +1,21 @@ + + + + + + Token Swapper + + +

Token Swapper

+
+ +
+
+ + + +
+ + + +