Skip to content

Commit ca5333e

Browse files
committed
feat: get detail of package using Sui JSON-RPC
1 parent 9f9a8d8 commit ca5333e

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/webview/App.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react";
1+
import React, { useEffect, useState } from "react";
22
import "./style.css";
33
import { useSuiClient, useSuiClientContext } from "@mysten/dapp-kit";
44
import { DEFAULT_ED25519_DERIVATION_PATH, Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
@@ -7,6 +7,7 @@ import { Input } from "./components/Input";
77
import { Button } from "./components/Button";
88
import { Aliases } from './components/Aliases';
99
import { sendMessage } from "./utils/wv_communicate_ext";
10+
import { getDetailPackage } from "./utils/suiPackage";
1011

1112
export interface IAppProps { }
1213

@@ -111,6 +112,19 @@ export const App: React.FunctionComponent<IAppProps> = ({ }: React.PropsWithChil
111112
}
112113
};
113114

115+
useEffect(() => {
116+
getDetailPackage(suiClient, "0xcab68c8cd7e80f3dd06466da6b2c083d1fd50ab3e9be8e32395c19b53021c064").then((data) => {
117+
const modules = Object.keys(data as {});
118+
119+
if (data) {
120+
for (const module of modules) {
121+
const { exposedFunctions } = data[module];
122+
console.log(exposedFunctions);
123+
}
124+
}
125+
}).catch(err => console.log(err));
126+
}, []);
127+
114128
return (
115129
<>
116130
<h1>Sui Simulator</h1>

src/webview/utils/suiPackage.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { SuiClient } from "@mysten/sui.js/client";
2+
3+
export const getDetailPackage = async (
4+
suiClient: SuiClient,
5+
packageId: string
6+
) => {
7+
try {
8+
const data = await suiClient.getNormalizedMoveModulesByPackage({
9+
package: packageId,
10+
});
11+
return data;
12+
} catch (err) {}
13+
};

0 commit comments

Comments
 (0)