Skip to content

Commit

Permalink
feat(jssdk): added factory functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Leechael committed Nov 11, 2023
1 parent 1783815 commit 156429d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontend/packages/sdk/src/OnChainRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface VersionedEndpoints extends Enum {
readonly asV1: Vec<Text>
}

interface CreateOptions {
export interface CreateOptions {
autoConnect?: boolean
clusterId?: string
workerId?: string
Expand Down
28 changes: 28 additions & 0 deletions frontend/packages/sdk/src/factory_functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ApiPromise, WsProvider } from '@polkadot/api'
import { PinkContractPromise } from './contracts/PinkContract'
import { type CreateOptions, OnChainRegistry } from './OnChainRegistry'
import { options } from './options'
import type { AbiLike } from './types'

export type GetClientOptions = {
transport: string | WsProvider
} & CreateOptions

export async function getClient(opts: GetClientOptions): Promise<OnChainRegistry> {
const { transport, ...rest } = opts
const provider = typeof transport === 'string' ? new WsProvider(transport) : transport
const api = await ApiPromise.create(options({ provider, noInitWarn: true }))
return await OnChainRegistry.create(api, rest)
}

export type GetContractOptions = {
client: OnChainRegistry
contractId: string
abi: AbiLike
}

export async function getContract(options: GetContractOptions): Promise<PinkContractPromise> {
const { client, contractId, abi } = options
const contractKey = await client.getContractKeyOrFail(contractId)
return new PinkContractPromise(client.api, client, abi, contractId, contractKey)
}
1 change: 1 addition & 0 deletions frontend/packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from './providers/types'
export * from './providers/EvmAccountMappingProvider'
export { default as createPruntimeClient } from './pruntime/createPruntimeClient'
export { default as signAndSend, SignAndSendError } from './utils/signAndSend'
export * from './factory_functions'

export const pruntimeRpc = pruntime_rpc
export type PhactoryAPI = pruntime_rpc.PhactoryAPI
Expand Down

0 comments on commit 156429d

Please sign in to comment.