-
Notifications
You must be signed in to change notification settings - Fork 0
/
sui.test.ts
53 lines (44 loc) · 1.52 KB
/
sui.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {Connection, Ed25519Keypair, JsonRpcProvider,} from '@mysten/sui.js';
const CHAIN_ID = 'testnet'
const KEY_STORE = ''; // AFMKGaJgwBPOzYIkg... ( cat $HOME/.sui/sui_config/sui.keystore )
describe('sui test', () => {
it('pk', async () => {
const keystoreBuf = Buffer.from(KEY_STORE, 'base64'); // this UInt8Array
const privateKeyBuf = keystoreBuf.slice(1);
const keypair = Ed25519Keypair.fromSecretKey(Uint8Array.from(privateKeyBuf));
const publicKeyBuf = Buffer.from(keypair.getPublicKey().toBytes());
console.log(`
private key: 0x${privateKeyBuf.toString('hex')}
public key : 0x${publicKeyBuf.toString('hex')}
address : ${keypair.getPublicKey().toSuiAddress()}
`)
});
it('getObject', async () => {
jest.setTimeout(30_000);
const provider = await getProvider();
const suiObjectResponse = await provider.getObject({
id: '0xfa493d3ad837c7a1673fb8720aceacd1a4a10b16100506cb050025dfd7e94e98',
options: {
showType: true,
showContent: true,
showBcs: true,
showOwner: true,
showPreviousTransaction: true,
showStorageRebate: true,
showDisplay: true,
},
});
console.log(json(suiObjectResponse));
});
});
function getProvider(): JsonRpcProvider {
return new JsonRpcProvider(
new Connection({
fullnode: `https://fullnode.${CHAIN_ID}.sui.io:443/`,
faucet: `https://faucet.${CHAIN_ID}.sui.io/gas`,
}),
);
}
function json(unknown: unknown) {
return JSON.stringify(unknown, null, 2);
}