Skip to content

Commit

Permalink
Merge pull request #19 from kartikaysaxena/main
Browse files Browse the repository at this point in the history
Added private key txn endpoint
  • Loading branch information
kartikaysaxena authored Dec 7, 2023
2 parents c0e873c + fe30fdc commit 4783766
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}`);
});
33 changes: 33 additions & 0 deletions server/src/privateKeyTxn.ts
Original file line number Diff line number Diff line change
@@ -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;

}

0 comments on commit 4783766

Please sign in to comment.