client.js 673 B

12345678910111213141516171819202122232425
  1. // Before running this script, make sure to run `yarn && yarn build` inside
  2. // the `ts` directory.
  3. const anchor = require('../../../../ts');
  4. const fs = require('fs');
  5. // Configure the local cluster.
  6. anchor.setProvider(anchor.Provider.local());
  7. // #region main
  8. async function main() {
  9. // Read the generated IDL.
  10. const idl = JSON.parse(fs.readFileSync('../idl.json', 'utf8'));
  11. // Address of the deployed program.
  12. const programId = new anchor.web3.PublicKey('<YOUR-PROGRAM-ID>');
  13. // Generate the program client from IDL.
  14. const program = new anchor.Program(idl, programId);
  15. // Execute the RPC.
  16. await program.rpc.initialize();
  17. }
  18. // #endregion main
  19. main();