Skip to content

Commit 1a5ae9e

Browse files
committed
add random code
1 parent 5b347f4 commit 1a5ae9e

File tree

7 files changed

+427
-0
lines changed

7 files changed

+427
-0
lines changed
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# @generated by Move, please check-in and do not edit manually.
2+
3+
[move]
4+
version = 2
5+
manifest_digest = "86A4BF572F164C40E35D11D469F863FCD29A214F773C837CB1DEA5C5EE1A92BE"
6+
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
7+
dependencies = [
8+
{ name = "Sui" },
9+
]
10+
11+
[[move.package]]
12+
name = "MoveStdlib"
13+
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" }
14+
15+
[[move.package]]
16+
name = "Sui"
17+
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" }
18+
19+
dependencies = [
20+
{ name = "MoveStdlib" },
21+
]
22+
23+
[move.toolchain-version]
24+
compiler-version = "1.33.0"
25+
edition = "2024.beta"
26+
flavor = "sui"
27+
28+
[env]
29+
30+
[env.testnet]
31+
chain-id = "4c78adac"
32+
original-published-id = "0xc80da11fbee3b9b74f3cf3fc7f013b6c12041b6ba68261019cf77fa3cbdc0966"
33+
latest-published-id = "0xc80da11fbee3b9b74f3cf3fc7f013b6c12041b6ba68261019cf77fa3cbdc0966"
34+
published-version = "1"
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[package]
2+
name = "cookbook"
3+
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
4+
# license = "" # e.g., "MIT", "GPL", "Apache 2.0"
5+
# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"]
6+
7+
[dependencies]
8+
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }
9+
10+
# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
11+
# Revision can be a branch, a tag, and a commit hash.
12+
# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" }
13+
14+
# For local dependencies use `local = path`. Path is relative to the package root
15+
# Local = { local = "../path/to" }
16+
17+
# To resolve a version conflict and force a specific version for dependency
18+
# override use `override = true`
19+
# Override = { local = "../conflicting/version", override = true }
20+
21+
[addresses]
22+
cookbook = "0x0"
23+
24+
# Named addresses will be accessible in Move as `@name`. They're also exported:
25+
# for example, `std = "0x1"` is exported by the Standard Library.
26+
# alice = "0xA11CE"
27+
28+
[dev-dependencies]
29+
# The dev-dependencies section allows overriding dependencies for `--test` and
30+
# `--dev` modes. You can introduce test-only dependencies here.
31+
# Local = { local = "../path/to/dev-build" }
32+
33+
[dev-addresses]
34+
# The dev-addresses section allows overwriting named addresses for the `--test`
35+
# and `--dev` modes.
36+
# alice = "0xB0B"
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
2+
import { SuiClient } from "@mysten/sui/client";
3+
import { Transaction } from "@mysten/sui/transactions";
4+
5+
import dotenv from "dotenv";
6+
dotenv.config();
7+
const MNEMONIC = process.env.MNEMONIC!;
8+
const keypair = Ed25519Keypair.deriveKeypair(MNEMONIC);
9+
10+
const PACKAGE_ID =
11+
"0xc80da11fbee3b9b74f3cf3fc7f013b6c12041b6ba68261019cf77fa3cbdc0966";
12+
const MODULE_NAME = "random";
13+
const FUNCTION_NAME = "roll_dice_nft";
14+
const FULLNODE_URL = "https://fullnode.testnet.sui.io:443";
15+
16+
const SUI_CLIENT = new SuiClient({ url: FULLNODE_URL });
17+
18+
(async () => {
19+
let tx = new Transaction();
20+
tx.moveCall({
21+
target: `${PACKAGE_ID}::${MODULE_NAME}::${FUNCTION_NAME}`,
22+
arguments: [tx.object("0x8")],
23+
});
24+
25+
try {
26+
const result = await SUI_CLIENT.signAndExecuteTransaction({
27+
transaction: tx,
28+
signer: keypair,
29+
options: {
30+
showEvents: true,
31+
},
32+
});
33+
34+
console.log(
35+
`signAndExecuteTransactionBlock result: ${JSON.stringify(
36+
result,
37+
null,
38+
2
39+
)}`
40+
);
41+
} catch (e) {
42+
console.error(e);
43+
}
44+
})();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "client",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"keywords": [],
9+
"author": "",
10+
"license": "ISC",
11+
"description": "",
12+
"dependencies": {
13+
"@mysten/sui": "^1.7.0",
14+
"dotenv": "^16.4.5"
15+
},
16+
"devDependencies": {
17+
"@types/node": "^22.5.1"
18+
}
19+
}

src/04_random/codes/cookbook/client/pnpm-lock.yaml

+243
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)