-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jssdk): added factory functions
- Loading branch information
Showing
3 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters