anchor/examples/tutorial/basic-0/client.js

28 lines
866 B
JavaScript
Raw Normal View History

2021-01-05 14:18:55 -08:00
// client.js is used to introduce the reader to generating clients from IDLs.
// It is not expected users directly test with this example. For a more
// ergonomic example, see `tests/basic-0.js` in this workspace.
2021-01-04 18:29:16 -08:00
const anchor = require('@project-serum/anchor');
2021-01-02 22:40:17 -08:00
// Configure the local cluster.
anchor.setProvider(anchor.Provider.local());
async function main() {
2021-01-04 18:29:16 -08:00
// #region main
2021-01-02 22:40:17 -08:00
// Read the generated IDL.
2021-01-04 18:29:16 -08:00
const idl = JSON.parse(require('fs').readFileSync('./target/idl/basic_0.json', 'utf8'));
2021-01-02 22:40:17 -08:00
// Address of the deployed program.
const programId = new anchor.web3.PublicKey('<YOUR-PROGRAM-ID>');
// Generate the program client from IDL.
const program = new anchor.Program(idl, programId);
// Execute the RPC.
await program.rpc.initialize();
2021-01-04 18:29:16 -08:00
// #endregion main
2021-01-02 22:40:17 -08:00
}
2021-01-04 18:29:16 -08:00
console.log('Running client.');
main().then(() => console.log('Success'));