diff --git a/server/index.ts b/server/index.ts index b28800c..08f3580 100644 --- a/server/index.ts +++ b/server/index.ts @@ -4,6 +4,7 @@ import checkBalance from './src/CheckBalance'; import { createAccount } from './src/CreateAccount'; import { genTxn } from './src/GenTxn'; import { doTransaction } from './src/Transaction'; +import { privateKeyTxn } from './src/privateKeyTxn'; const app = express(); const PORT = 5500; @@ -35,6 +36,12 @@ app.post('/getBalance', async (req: Request, res: Response) => { res.json(await checkBalance(req.body)); }); +app.post('/transaction', async (req: Request, res: Response) => { + privateKeyTxn(req.body).then((tx) => { + res.json({ tx }); + }); +}); + app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); }); diff --git a/server/src/privateKeyTxn.ts b/server/src/privateKeyTxn.ts new file mode 100644 index 0000000..2cb4cc5 --- /dev/null +++ b/server/src/privateKeyTxn.ts @@ -0,0 +1,33 @@ +import { Account,Aptos,Ed25519PrivateKey } from "@aptos-labs/ts-sdk"; + + type Request = { + pk: string; + recipient: string; + amount: number; + } + + + + +export async function privateKeyTxn(request:Request) { + + const aptos = new Aptos(); + + const requestBody: Request = request; + const { recipient, pk, amount } = requestBody; + + // const pk = "0x4be5a633898eb5040519eab1494309f6966d977613d25500784b034a41f377a4"; + const privateKey = new Ed25519PrivateKey(pk); + const account = Account.fromPrivateKey({ privateKey: privateKey }); + + const txn = await aptos.transferCoinTransaction({ + sender: account, + recipient: recipient, + amount: amount, + }); + const txn1 = await aptos.signAndSubmitTransaction({ signer: account, transaction: txn }); + console.log(txn1); + return txn1; + +} +