client.js 876 B

1234567891011121314151617181920212223242526272829
  1. // client.js is used to introduce the reader to generating clients from IDLs.
  2. // It is not expected users directly test with this example. For a more
  3. // ergonomic example, see `tests/basic-0.js` in this workspace.
  4. const anchor = require("@coral-xyz/anchor");
  5. // Configure the local cluster.
  6. anchor.setProvider(anchor.AnchorProvider.local());
  7. async function main() {
  8. // #region main
  9. // Read the generated IDL.
  10. const idl = JSON.parse(
  11. require("fs").readFileSync("./target/idl/basic_0.json", "utf8")
  12. );
  13. // Address of the deployed program.
  14. const programId = new anchor.web3.PublicKey("<YOUR-PROGRAM-ID>");
  15. // Generate the program client from IDL.
  16. const program = new anchor.Program(idl, programId);
  17. // Execute the RPC.
  18. await program.rpc.initialize();
  19. // #endregion main
  20. }
  21. console.log("Running client.");
  22. main().then(() => console.log("Success"));