@@ -903,17 +903,51 @@ class AleoNetworkClient {
903903 * const expectedSource = "program hello_hello.aleo;\n\nfunction hello:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n"
904904 * assert.equal(program, expectedSource);
905905 */
906- async getProgram ( programId : string ) : Promise < string > {
906+ async getProgram ( programId : string , version ?: number ) : Promise < string > {
907907 try {
908- this . ctx = { "X-ALEO-METHOD" : "getProgram" } ;
909- return await this . fetchData < string > ( "/program/" + programId ) ;
908+ this . ctx = { "X-ALEO-METHOD" : "getProgramVersion" } ;
909+ if ( typeof version === "number" ) {
910+ return await this . fetchData < string > (
911+ `/program/${ programId } /${ version } ` ,
912+ ) ;
913+ } else {
914+ return await this . fetchData < string > ( "/program/" + programId ) ;
915+ }
910916 } catch ( error ) {
911917 throw new Error ( `Error fetching program ${ programId } : ${ error } ` ) ;
912918 } finally {
913919 this . ctx = { } ;
914920 }
915921 }
916922
923+ /**
924+ * Returns the current program edition deployed on Aleo.
925+ *
926+ * @param {string } programId The program ID of a program deployed to the Aleo Network.
927+ * @returns {Promise<number> } Source code of the program.
928+ *
929+ * @example
930+ * import { AleoNetworkClient } from "@provablehq/sdk/mainnet.js";
931+ *
932+ * // Create a network client.
933+ * const networkClient = new AleoNetworkClient("http://api.explorer.provable.com/v1", undefined);
934+ *
935+ * const programVersion = networkClient.getProgramSource("hello_hello.aleo");
936+ * assert.equal(programVersion, 1);
937+ */
938+ async getLatestProgramEdition ( programId : string ) : Promise < string > {
939+ try {
940+ this . ctx = { "X-ALEO-METHOD" : "getLatestProgramEdition" } ;
941+ return await this . fetchData < string > ( "/program/" + programId + "/latestEdition" ) ;
942+ } catch ( error ) {
943+ throw new Error ( `Error fetching program ${ programId } : ${ error } ` ) ;
944+ } finally {
945+ this . ctx = { } ;
946+ }
947+ }
948+
949+
950+
917951 /**
918952 * Returns a program object from a program ID or program source code.
919953 *
0 commit comments