forked from FilOzone/synapse-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
68 lines (63 loc) · 2.06 KB
/
Copy pathindex.ts
File metadata and controls
68 lines (63 loc) · 2.06 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {
type Account,
type Address,
type Chain,
type Client,
type GetContractErrorType,
type Transport,
getContract as viemGetContract,
} from 'viem'
import { asChain } from '../chains.ts'
export * from './data-set-live.ts'
export * from './find-piece-ids-by-cid.ts'
export * from './get-active-piece-count.ts'
export * from './get-active-pieces.ts'
export * from './get-data-set-leaf-count.ts'
export * from './get-data-set-listener.ts'
export * from './get-data-set-storage-provider.ts'
export * from './get-dataset-size.ts'
export * from './get-next-challenge-epoch.ts'
export * from './get-next-piece-id.ts'
export * from './get-pieces.ts'
export * from './get-scheduled-removals.ts'
export namespace getContract {
export type OptionsType = {
/** The client to use to get the contract. */
client: Client<Transport, Chain, Account>
/** The address of the contract. If not provided, the default is the PDP Verifier contract address for the chain. */
address?: Address
}
export type OutputType = ReturnType<typeof viemGetContract>
export type ErrorType = asChain.ErrorType | GetContractErrorType
}
/**
* Get the PDP Verifier contract
*
* @example
* ```ts
* import { getContract } from '@filoz/synapse-core/pdp-verifier'
* import { calibration } from '@filoz/synapse-core/chains'
* import { createPublicClient, http } from 'viem'
*
* const client = createPublicClient({
* chain: calibration,
* transport: http(),
* })
*
* const contract = getContract({ client })
* const dataSetId = 1n
* const isLive = await contract.read.dataSetLive([dataSetId])
* ```
*
* @param options - {@link getContract.OptionsType}
* @returns [Contract](https://viem.sh/docs/contract/getContract) {@link getContract.OutputType}
* @throws Errors {@link getContract.ErrorType}
*/
export function getContract(options: getContract.OptionsType): getContract.OutputType {
const chain = asChain(options.client.chain)
return viemGetContract({
address: options.address ?? chain.contracts.pdp.address,
abi: chain.contracts.pdp.abi,
client: options.client,
})
}