pythexample.ts 862 B

123456789101112131415161718192021222324252627282930
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { Program } from "@coral-xyz/anchor";
  3. import { Pythexample } from "../target/types/pythexample";
  4. describe("pythexample", () => {
  5. // Configure the client to use the local cluster.
  6. anchor.setProvider(anchor.AnchorProvider.env());
  7. const program = anchor.workspace.Pythexample as Program<Pythexample>;
  8. const PYTH_FEED_ID = new anchor.web3.PublicKey(
  9. "H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG"
  10. );
  11. it("Check SOL_USD Price", async () => {
  12. const tx = await program.methods
  13. .readPrice()
  14. .accounts({
  15. priceFeed: PYTH_FEED_ID,
  16. systemProgram: anchor.web3.SystemProgram.programId,
  17. clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
  18. })
  19. .rpc();
  20. console.log(
  21. "Your transaction signature, find the price in the program logs",
  22. tx
  23. );
  24. });
  25. });