client.js 866 B

123456789101112131415161718192021222324252627
  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('@project-serum/anchor');
  5. // Configure the local cluster.
  6. anchor.setProvider(anchor.Provider.local());
  7. async function main() {
  8. // #region main
  9. // Read the generated IDL.
  10. const idl = JSON.parse(require('fs').readFileSync('./target/idl/basic_0.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. // #endregion main
  18. }
  19. console.log('Running client.');
  20. main().then(() => console.log('Success'));