Created
July 24, 2022 09:53
-
-
Save aeither/2ea88add9b527faf930357533efe3702 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
clusterApiUrl, | |
Connection, | |
Keypair, | |
LAMPORTS_PER_SOL, | |
PublicKey, | |
sendAndConfirmTransaction, | |
Transaction, | |
TransactionInstruction, | |
TransactionSignature, | |
} from "@solana/web3.js"; | |
import base58 from "bs58"; | |
import Dotenv from "dotenv"; | |
Dotenv.config(); | |
let programId = new PublicKey("<YOUR_PROGRAM_ID>"); | |
const connection = new Connection(clusterApiUrl("devnet"), "confirmed"); | |
async function main() { | |
const secret = process.env.PRIVATE_KEY || ""; | |
const secretKey = base58.decode(secret); | |
const payer = Keypair.fromSecretKey(secretKey); | |
await connection.requestAirdrop(payer.publicKey, LAMPORTS_PER_SOL * 1); | |
const transactionSignature = await sayHello(payer); | |
console.log( | |
`Transaction: https://explorer.solana.com/tx/${transactionSignature}?cluster=devnet` | |
); | |
} | |
main() | |
.then(() => { | |
console.log("Finished successfully"); | |
}) | |
.catch((error) => { | |
console.error(error); | |
}); | |
export async function sayHello(payer: Keypair): Promise<TransactionSignature> { | |
const transaction = new Transaction(); | |
const instruction = new TransactionInstruction({ | |
keys: [], | |
programId, | |
}); | |
transaction.add(instruction); | |
const transactionSignature = await sendAndConfirmTransaction( | |
connection, | |
transaction, | |
[payer] | |
); | |
return transactionSignature; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment