123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import {
- Connection,
- Keypair,
- sendAndConfirmTransaction,
- Transaction,
- TransactionInstruction,
- } from '@solana/web3.js';
- function createKeypairFromFile(path: string): Keypair {
- return Keypair.fromSecretKey(
- Buffer.from(JSON.parse(require('fs').readFileSync(path, "utf-8")))
- )
- };
- describe("hello-solana", () => {
- // Loading these from local files for development
- //
- const connection = new Connection(`http://localhost:8899`, 'confirmed');
- const payer = createKeypairFromFile(require('os').homedir() + '/.config/solana/id.json');
- const program = createKeypairFromFile('./program/target/so/program-keypair.json');
-
- it("Say hello!", async () => {
- // We set up our instruction first.
- //
- let ix = new TransactionInstruction({
- keys: [
- {pubkey: payer.publicKey, isSigner: true, isWritable: true}
- ],
- programId: program.publicKey,
- data: Buffer.alloc(0), // No data
- });
- // Now we send the transaction over RPC
- //
- await sendAndConfirmTransaction(
- connection,
- new Transaction().add(ix), // Add our instruction (you can add more than one)
- [payer]
- );
- });
- });
-
|