-
Notifications
You must be signed in to change notification settings - Fork 10
/
authz_grant.ts
44 lines (36 loc) · 1.32 KB
/
authz_grant.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
import * as BIP39 from "bip39";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import { randomMnemonic } from "../lib/util/address";
import { CarbonSDK } from "./_sdk";
import "./_setup";
(async () => {
const mnemonics = process.env.MNEMONICS ?? BIP39.generateMnemonic();
console.log("mnemonics:", mnemonics);
const sdk = await CarbonSDK.instance({
network: CarbonSDK.Network.LocalHost,
config: {
tmRpcUrl: process.env.TRPC_ENDPOINT,
},
});
const connectedSDK = await sdk.connectWithMnemonic(mnemonics);
console.log("connected sdk");
const randomMnemonics = randomMnemonic()
const sdkInstance = await CarbonSDK.instanceWithMnemonic(randomMnemonics, { network: CarbonSDK.Network.LocalHost })
const grantee = sdkInstance?.wallet?.bech32Address ?? ''
dayjs.extend(utc)
const expiry: Date = dayjs.utc().add(60, "hours").toDate()
const params = {
grantee,
expiry,
existingGrantee: false,
}
const result = await connectedSDK.grant.grantAuthAndAllowance(params);
// Copy the following to populate the params in _test-signless-create-order.ts
console.log(result)
const queryParams = {
grantee,
}
const queryResult = await connectedSDK.grant.queryGranteeDetails(queryParams);
console.log(queryResult)
})().catch(console.error).finally(() => process.exit(0));