Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions scripts/src/input_objects_exercise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const main = async () => {
*
* Create a new Transaction instance from the @mysten/sui/transactions module.
*/

const tx = new Transaction();
/**
* Task 2:
*
Expand All @@ -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:
*
Expand All @@ -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:
*
Expand All @@ -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 });


/**
Expand All @@ -86,4 +104,4 @@ const main = async () => {
*/
};

main();
main().catch(console.error);
17 changes: 14 additions & 3 deletions scripts/src/return_objects_exercise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
*
Expand All @@ -61,7 +67,7 @@ const main = async () => {
*
* HINT: Use `suiAddress`` to transfer the object to your address.
*/

tx.transferObjects([nft], suiAddress);

/**
* Task 4:
Expand All @@ -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!
*
Expand Down
47 changes: 41 additions & 6 deletions scripts/src/scavenger_hunt_exercise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,61 @@ 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:
*
* 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:
*
* Transfer the `SUI` coin to your account.
*/


tx.transferObjects([coin], keypair.getPublicKey().toSuiAddress());
/**
* Task 6:
*
Expand All @@ -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!
*
Expand All @@ -85,5 +121,4 @@ const main = async () => {
* Verify the transaction on the Sui Explorer: https://suiscan.xyz/testnet/home
*/
};

main();
main();