feat: shinzohub client package#226
Conversation
| export function hexToShinzoAddress(value: string, options: ShinzoAddressOptions = {}): ShinzoAddress { | ||
| const prefix = options.prefix ?? SHINZO_BECH32_PREFIX; | ||
| const hexAddress = normalizeHexAddress(value); | ||
| return encodeBech32(prefix, hexToBytes(hexAddress)) as ShinzoAddress; | ||
| } |
There was a problem hiding this comment.
note: this function can be used in registration, faucet and studio apps for switching from EVM to Shinzo address.
| export const shinzoHubDevelop = defineChain({ | ||
| id: 91273002, | ||
| name: "ShinzoHub Develop", | ||
| nativeCurrency: currency, | ||
| rpcUrls: { | ||
| default: { http: ["http://rpc.develop.devnet.shinzo.network:8545"] }, | ||
| cosmosRest: { http: ["http://rpc.develop.devnet.shinzo.network:1317"] }, | ||
| cometRpc: { http: ["http://rpc.develop.devnet.shinzo.network:26657"] }, | ||
| }, | ||
| }); |
There was a problem hiding this comment.
note: the library defines different shinzohub environments
| export async function createView(client: Client, parameters: CreateViewParameters): Promise<Hex> { | ||
| const tx = buildCreateViewTransaction(parameters); | ||
| return sendTransaction(client, { | ||
| to: tx.to, | ||
| data: tx.data, | ||
| chain: client.chain, | ||
| account: parameters.account ?? (client as { account?: Account | Address }).account, | ||
| } as any); | ||
| } |
There was a problem hiding this comment.
note: this function sends a transaction to register a view on shinzohub
| export async function listViews( | ||
| client: Client, | ||
| parameters: ListViewsParameters = {}, | ||
| ): Promise<ListViewsResult> { | ||
| const fetchFn = globalThis.fetch?.bind(globalThis); | ||
| if (!fetchFn) { | ||
| throw new Error("No fetch implementation is available."); | ||
| } | ||
|
|
||
| const response = await requestJson<ListViewsWireResponse>( | ||
| fetchFn, | ||
| buildListViewsUrl(getCosmosRestUrl(client, parameters), parameters), | ||
| ); | ||
|
|
||
| return { | ||
| views: (response.views ?? []).map(toView), | ||
| pagination: toPageResponse(response.pagination), | ||
| }; | ||
| } |
There was a problem hiding this comment.
note: the /shinzonetwork/view/v1/views endpoint has many many acceptable query params. This function simplifies it, adds full typing and docs on each field.
| export function createShinzoHubClient<TClient extends Client>(client: TClient) { | ||
| return client.extend(shinzoHubActions); | ||
| } |
There was a problem hiding this comment.
note: main entry point into the library
| } | ||
|
|
||
| const hexAddress = shinzoAddressToHex(input, options); | ||
| return hexToShinzoAddress(hexAddress, options); |
There was a problem hiding this comment.
[question]: why are we converting shinzoAddress to hex and then back to shinzoAddress here?
There was a problem hiding this comment.
it was done to reuse the address validation, but i agree that it brought the overhead. Extracted validateShinzoAddress out of the shinzo address-related functions and reused it more nicely.
NiranjanaBinoy
left a comment
There was a problem hiding this comment.
I left a question, otherwise the changes looks good to me.
* feat(lenses): add view bundling to lenses package * feat(studio): apply shinzohub package to deploy a view * fix(studio): build
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
shinzo-studio | 0cca34a | Commit Preview URL Branch Preview URL |
May 23 2026, 04:48 AM |
Closes #222
Read #220 for description of why do we need this package. Quick recap: all big APIs should have their client libraries to centralize the usage and update it in only one place. Plus, ShinzoHub developers can do it themselves when they create new changes.
How it's done: