diff --git a/scripts/src/input_objects_exercise.ts b/scripts/src/input_objects_exercise.ts index df578cb..8c271f3 100644 --- a/scripts/src/input_objects_exercise.ts +++ b/scripts/src/input_objects_exercise.ts @@ -39,7 +39,7 @@ const main = async () => { * * Create a new Transaction instance from the @mysten/sui/transactions module. */ - + const tx = new Transaction(); /** * Task 2: * @@ -50,7 +50,7 @@ const main = async () => { * Resources: * - SplitCoins: https://sdk.mystenlabs.com/typescript/transaction-building/basics */ - + const [feeCoin] = tx.splitCoins(tx.gas, [10]); /** * Task 3: * @@ -64,7 +64,13 @@ const main = async () => { * - Object inputs: https://sdk.mystenlabs.com/typescript/transaction-building/basics#object-references */ - + tx.moveCall({ + target: `${PACKAGE_ID}::counter::increment`, + arguments: [ + tx.object(COUNTER_OBJECT_ID), // The counter object as input + tx.object(feeCoin), // The fee coin as payment + ], + }); /** * Task 4: * @@ -75,6 +81,18 @@ const main = async () => { * Resources: * - Observing transaction results: https://sdk.mystenlabs.com/typescript/transaction-building/basics#observing-the-results-of-a-transaction */ + const result = await suiClient.signAndExecuteTransaction({ + signer: keypair, + transaction: tx, + options: { + showEffects: true, + showObjectChanges: true, + showBalanceChanges: true, + showEvents: true, + }, + }); + + await suiClient.waitForTransaction({ digest: result.digest }); /** @@ -86,4 +104,4 @@ const main = async () => { */ }; -main(); +main().catch(console.error); diff --git a/scripts/src/return_objects_exercise.ts b/scripts/src/return_objects_exercise.ts index d27f246..6df3d13 100644 --- a/scripts/src/return_objects_exercise.ts +++ b/scripts/src/return_objects_exercise.ts @@ -34,11 +34,14 @@ const suiClient = new SuiClient({ url: rpcUrl }); * - https://sdk.mystenlabs.com/typescript/transaction-building/basics#transactions */ const main = async () => { + + /** * Task 1: * * Create a new Transaction instance from the @mysten/sui/transactions module. */ + const tx = new Transaction(); /** * Task 2: @@ -51,7 +54,10 @@ const main = async () => { * HINT: The arguments and typeArguments arguments are optional since this function does not take * any arguments or type arguments. */ - + const [nft] = tx.moveCall({ + target: `${PACKAGE_ID}::sui_nft::new`, + arguments: [], + }); /** * Task 3: * @@ -61,7 +67,7 @@ const main = async () => { * * HINT: Use `suiAddress`` to transfer the object to your address. */ - + tx.transferObjects([nft], suiAddress); /** * Task 4: @@ -71,7 +77,12 @@ const main = async () => { * Print the result to the console. */ - + const result = await suiClient.signAndExecuteTransaction({ + signer: keypair, + transaction: tx, + }); + + console.log("Transaction digest:", result.digest); /** * Task 5: Run the script with the command below and ensure it works! * diff --git a/scripts/src/scavenger_hunt_exercise.ts b/scripts/src/scavenger_hunt_exercise.ts index 2ad0b52..7427964 100644 --- a/scripts/src/scavenger_hunt_exercise.ts +++ b/scripts/src/scavenger_hunt_exercise.ts @@ -33,23 +33,41 @@ const suiClient = new SuiClient({ url: rpcUrl }); * - https://sdk.mystenlabs.com/typescript/transaction-building/basics#transactions */ const main = async () => { - /** + /** * Task 1: * * Create a new Transaction instance from the @mysten/sui/transactions module. */ - /** + const tx = new Transaction(); + + // Read the vault to get the actual code on-chain + const vaultObject = await suiClient.getObject({ + id: VAULT_ID, + options: { showContent: true }, + }); + const code = Number( + // @ts-ignore quick field extract from Move object + vaultObject.data?.content?.fields?.code ?? 0 + ); + /** * Task 2: * * Create a new key using the `key::new` function. */ + const [key] = tx.moveCall({ + target: `${PACKAGE_ID}::key::new`, + }); - /** + /** * Task 3: * * Set the key code correctly using the `key::set_code` function. */ + tx.moveCall({ + target: `${PACKAGE_ID}::key::set_code`, + arguments: [tx.object(key), tx.pure.u64(code)], + }); /** * Task 4: @@ -57,6 +75,11 @@ const main = async () => { * Use the key to withdraw the `SUI` coin from the vault using the `vault::withdraw` function. */ + const [coin] = tx.moveCall({ + target: `${PACKAGE_ID}::vault::withdraw`, + typeArguments: ['0x2::sui::SUI'], + arguments: [tx.object(VAULT_ID), tx.object(key)], + }); /** * Task 5: @@ -64,7 +87,7 @@ const main = async () => { * Transfer the `SUI` coin to your account. */ - + tx.transferObjects([coin], keypair.getPublicKey().toSuiAddress()); /** * Task 6: * @@ -76,7 +99,20 @@ const main = async () => { * - Observing transaction results: https://sdk.mystenlabs.com/typescript/transaction-building/basics#observing-the-results-of-a-transaction */ + const result = await suiClient.signAndExecuteTransaction({ + signer: keypair, + transaction: tx, + options: { + showEffects: true, + showObjectChanges: true, + showBalanceChanges: true, + showEvents: true, + }, + }); + await suiClient.waitForTransaction({ digest: result.digest }); + console.log("Digest:", result.digest); + console.log("Explorer:", `https://suiexplorer.com/txblock/${result.digest}?network=testnet`); /** * Task 7: Run the script with the command below and ensure it works! * @@ -85,5 +121,4 @@ const main = async () => { * Verify the transaction on the Sui Explorer: https://suiscan.xyz/testnet/home */ }; - -main(); +main(); \ No newline at end of file