Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mint token #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/address.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const PRIVATE_KEY = "";
export const PUBLIC_KEY = "";
export const PRIVATE_KEY = env.PRIVATE_KEY;
export const PUBLIC_KEY = "2ieyZg4CJLJvxhejhX5k2qkdbeJjGo2i4zsNZ2XupGFv";

export const TOKEN_MINT_ADDRESS = "";
export const TOKEN_MINT_ADDRESS = env.TOKEN_MINT_ADDRESS;
40 changes: 27 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
require('dotenv').config();
import express from 'express';
import bodyParser from 'body-parser';
import { burnTokens, mintTokens, sendNativeTokens } from './mintTokens';

const app = express();

// Middleware to parse JSON bodies
app.use(bodyParser.json());

app.post('/helius', async(req, res) => {
const fromAddress = req.body.fromAddress;
const toAddress = req.body.toAddress;
const amount = req.body.amount;
const type = "received_native_sol";
// Endpoint to handle incoming requests
app.post('/helius', async (req, res) => {
const { fromAddress, toAddress, amount } = req.body;
const type = "received_native_sol"; // This could be dynamic based on your logic

if (type === "received_native_sol") {
await mintTokens(fromAddress, toAddress, amount);
} else {
// What could go wrong here?
await burnTokens(fromAddress, toAddress, amount);
await sendNativeTokens(fromAddress, toAddress, amount);
// Input validation
if (!fromAddress || !toAddress || !amount) {
return res.status(400).send('Invalid request: Missing parameters');
}

res.send('Transaction successful');
try {
if (type === "received_native_sol") {
// Mint tokens when native SOL is received
await mintTokens(fromAddress, toAddress, amount);
} else {
// Handle other types of transactions
await burnTokens(fromAddress, toAddress, amount);
await sendNativeTokens(fromAddress, toAddress, amount);
}

res.status(200).send('Transaction successful');
} catch (error) {
console.error('Error processing transaction:', error);
res.status(500).send('Transaction failed');
}
});

// Start the server
app.listen(3000, () => {
console.log('Server is running on port 3000');
console.log('Server is running on port 3000');
});
43 changes: 37 additions & 6 deletions src/mintTokens.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@

export const mintTokens = async (fromAddress: string, toAddress: string, amount: number) => {
import {
Connection,
Keypair,
PublicKey,
} from '@solana/web3.js';
import {
getOrCreateAssociatedTokenAccount,
mintTo,
} from '@solana/spl-token';

export const mintTokens = async (connection: Connection, payer: Keypair, mintAddress: PublicKey, recipientAddress: PublicKey, amount: number) => {
console.log("Minting tokens");
}

export const burnTokens = async (fromAddress: string, toAddress: string, amount: number) => {
const recipientTokenAccount = await getOrCreateAssociatedTokenAccount(
connection,
payer,
mintAddress,
recipientAddress
);

await mintTo(
connection,
payer,
mintAddress,
recipientTokenAccount.address,
payer.publicKey,
amount
);

console.log(`Minted ${amount} tokens to ${recipientAddress.toString()}`);
};

export const burnTokens = async (fromAddress: PublicKey, toAddress: PublicKey, amount: number) => {
console.log("Burning tokens");
}

};


export const sendNativeTokens = async (fromAddress: string, toAddress: string, amount: number) => {
export const sendNativeTokens = async (fromAddress: PublicKey, toAddress: PublicKey, amount: number) => {
console.log("Sending native tokens");
}

};