sol crypto terminal
This commit is contained in:
parent
eddf32a804
commit
d225843ad9
25
crypto/sol/app.py
Normal file
25
crypto/sol/app.py
Normal file
@ -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)
|
4
crypto/sol/r.txt
Normal file
4
crypto/sol/r.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
flask
|
||||||
|
solana
|
||||||
|
idna
|
||||||
|
httpx
|
28
crypto/sol/static/app.js
Normal file
28
crypto/sol/static/app.js
Normal file
@ -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));
|
||||||
|
});
|
21
crypto/sol/templates/index.html
Normal file
21
crypto/sol/templates/index.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Token Swapper</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Token Swapper</h1>
|
||||||
|
<div>
|
||||||
|
<button id="connectWallet">Connect Phantom Wallet</button>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input type="text" id="tokenName" placeholder="Enter Token Name">
|
||||||
|
<input type="number" id="amount" placeholder="Enter Amount">
|
||||||
|
<button id="swapToken">Swap Token</button>
|
||||||
|
</div>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@solana/web3.js"></script>
|
||||||
|
<script src="app.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user