client.js 729 B

123456789101112131415161718192021222324252627
  1. // TODO: replace path once the package is published.
  2. //
  3. // Before running this script, make sure to run `yarn && yarn build` inside
  4. // the `ts` directory.
  5. const anchor = require('../../../../ts');
  6. const fs = require('fs');
  7. // Configure the local cluster.
  8. anchor.setProvider(anchor.Provider.local());
  9. // #region main
  10. async function main() {
  11. // Read the generated IDL.
  12. const idl = JSON.parse(fs.readFileSync('../idl.json', 'utf8'));
  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. }
  20. // #endregion main
  21. main();