Skip to main content

code-reference

@nevermined-io/sdk

@nevermined-io/sdk - v3.0.19

Table of contents

References

Enumerations

Classes

Interfaces

Type Aliases

Variables

Functions

References

LoggerInstance

Renames and re-exports Logger

Type Aliases

ConditionMethod

Ƭ ConditionMethod: "fulfill" | "fulfillForDelegate"

Defined in

src/types/ContractTypes.ts:10


ConditionType

Ƭ ConditionType: "lockPayment" | "escrowPayment" | "nftHolder" | "transferNFT"

Defined in

src/types/DDOTypes.ts:606


EncryptionMethod

Ƭ EncryptionMethod: "PSK-RSA" | "PSK-ECDSA"

Defined in

src/constants/AssetConstants.ts:4


EventResult

Ƭ EventResult: Promise\<any[]>

Defined in

src/types/EventTypes.ts:25


NeverminedNFTType

Ƭ NeverminedNFTType: NeverminedNFT721Type | NeverminedNFT1155Type

Defined in

src/types/GeneralTypes.ts:31


ParameterType

Ƭ ParameterType: string | number | number[] | NvmAccount | BabyjubPublicKey | Service | ServiceType | TxParameters

Defined in

src/keeper/contracts/templates/AgreementTemplate.abstract.ts:23


PricedMetadataInformation

Ƭ PricedMetadataInformation: Object

Type declaration

NameType
attributes{ additionalInformation: { priceHighestDenomination: number } ; main: { price: string } }
attributes.additionalInformation{ priceHighestDenomination: number }
attributes.additionalInformation.priceHighestDenominationnumber
attributes.main{ price: string }
attributes.main.pricestring

Defined in

src/types/DDOTypes.ts:644


ProvenanceEvent

Ƭ ProvenanceEvent\<T>: T extends WAS_GENERATED_BY ? WasGeneratedByEvent : T extends USED ? UsedEvent : T extends WAS_DERIVED_FROM ? WasDerivedFromEvent : T extends WAS_ASSOCIATED_WITH ? WasAssociatedWithEvent : T extends ACTED_ON_BEHALF ? ActedOnBehalfEvent : WasGeneratedByEvent | UsedEvent | WasDerivedFromEvent | WasAssociatedWithEvent | ActedOnBehalfEvent

Type parameters

NameType
Textends ProvenanceMethod | any = any

Defined in

src/keeper/contracts/Provenance.ts:80


Service

Ƭ Service\<T>: T extends "authorization" ? ServiceAuthorization : T extends "metadata" ? ServiceMetadata : T extends "nft-access" ? ServiceNFTAccess : T extends "nft-sales" ? ServiceNFTSales : T extends "access" ? ServiceAccess : T extends "compute" ? ServiceCompute : T extends "default" ? ServiceCommon : ServiceCommon

Type parameters

NameType
Textends ServiceType | "default" = "default"

Defined in

src/types/DDOTypes.ts:765


ServiceType

Ƭ ServiceType: "authorization" | "metadata" | "access" | "compute" | "workflow" | "nft-access" | "nft-sales" | "nft-sales-proof"

Defined in

src/types/DDOTypes.ts:608

Variables

ConditionStateNames

Const ConditionStateNames: string[]

Defined in

src/types/ContractTypes.ts:8


DEFAULT_ENCRYPTION_METHOD

Const DEFAULT_ENCRYPTION_METHOD: EncryptionMethod

Defined in

src/constants/AssetConstants.ts:7


DEFAULT_REGISTRATION_ACTIVITY_ID

Const DEFAULT_REGISTRATION_ACTIVITY_ID: "AssetRegistration"

Identifies the default Provenance Activity Id to be recorded on-chain in the DIDRegistry Smart Contract when an asset is registered. It associates to the new DID created the 'Asset Registration' activity. (@see https://docs.nevermined.io/docs/architecture/specs/Spec-PROVENANCE#provenance-relations)

Defined in

src/keeper/contracts/Provenance.ts:7


DEPENDENCIES_RELEASE_CONDITION

Const DEPENDENCIES_RELEASE_CONDITION: string[]

Defined in

src/ddo/DDO.ts:36


DefaultPaymentAttributes

Const DefaultPaymentAttributes: PaymentAttributes[]

Defined in

src/types/DDOTypes.ts:74


Logger

Const Logger: Logger

Defined in

src/models/Logger.ts:43


NETWORK_FEE_DENOMINATOR

Const NETWORK_FEE_DENOMINATOR: 10000n

Defined in

src/constants/AssetConstants.ts:1


SALES_SERVICES

Const SALES_SERVICES: string[]

Defined in

src/ddo/DDO.ts:34


ZeroAddress

Const ZeroAddress: "0x0000000000000000000000000000000000000000"

Defined in

src/constants/AssetConstants.ts:10


apiPath

Const apiPath: "/api/v1/metadata/assets/ddo"

Defined in

src/services/metadata/MetadataService.ts:8


defaultNeverminedNFTType

Const defaultNeverminedNFTType: Object

Type declaration

NameType
1155NeverminedNFT1155Type
721NeverminedNFT721Type

Defined in

src/types/GeneralTypes.ts:40


ercOfNeverminedNFTType

Const ercOfNeverminedNFTType: Object

Type declaration

NameType
nft1155ERCType
nft1155-creditERCType
nft721ERCType
nft721-subscriptionERCType

Defined in

src/types/GeneralTypes.ts:33


serviceIndex

Const serviceIndex: Object

Type declaration

NameType
accessnumber
access-proofnumber
authorizationnumber
computenumber
metadatanumber
nft-accessnumber
nft-access-proofnumber
nft-salesnumber
nft-sales-proofnumber
nft721-accessnumber
nft721-access-proofnumber
nft721-salesnumber
nft721-sales-proofnumber
workflownumber

Defined in

src/types/DDOTypes.ts:618


servicePath

Const servicePath: "/api/v1/metadata/assets/service"

Defined in

src/services/metadata/MetadataService.ts:9

Functions

_sleep

_sleep(ms): Promise\<unknown>

Parameters

NameType
msnumber

Returns

Promise\<unknown>

Defined in

src/common/helpers.ts:47


buildQuery

buildQuery(url, query?): any

Parameters

NameType
urlstring
query?SearchQuery

Returns

any

Defined in

src/common/helpers.ts:7


checkContractExists

checkContractExists(contractAddress, client): Promise\<boolean>

Given a contract address it checks if the contract exists on the blockchain.

Parameters

NameTypeDescription
contractAddressstringthe contract address
clientObjectthe client to interact with the blockchain
client.accountundefinedThe Account of the Client.
client.batch?ObjectFlags for batch settings.
client.batch.multicall?boolean | { batchSize?: number ; wait?: number }Toggle to enable eth_call multicall aggregation.
client.cacheTimenumberTime (in ms) that cached data will remain in memory.
client.call(parameters: CallParameters\<undefined | Chain>) => Promise\<CallReturnType>Executes a new message call immediately without submitting a transaction to the network. - Docs: https://viem.sh/docs/actions/public/call - JSON-RPC Methods: eth_call Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const data = await client.call({ account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', })
client.ccipRead?false | { request?: (parameters: CcipRequestParameters) => Promise\<`0x${string}`> }CCIP Read configuration.
client.chainundefined | ChainChain for the client.
client.createBlockFilter() => Promise\<{ id: `0x${string}` ; request: EIP1193RequestFn\<readonly [{ Method: "eth_getFilterChanges" ; Parameters: [filterId: `0x${string}`] ; ReturnType: `0x${string}`[] | RpcLog[] }, { Method: "eth_getFilterLogs" ; Parameters: [filterId: `0x${string}`] ; ReturnType: RpcLog[] }, { Method: "eth_uninstallFilter" ; Parameters: [filterId: `0x${string}`] ; ReturnType: boolean }]> ; type: "block" }>Creates a Filter to listen for new block hashes that can be used with getFilterChanges. - Docs: https://viem.sh/docs/actions/public/createBlockFilter - JSON-RPC Methods: eth_newBlockFilter Example ts import { createPublicClient, createBlockFilter, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const filter = await createBlockFilter(client) // { id: "0x345a6572337856574a76364e457a4366", type: 'block' }
client.createContractEventFilter\<TAbi, TEventName, TArgs, TStrict, TFromBlock, TToBlock>(args: CreateContractEventFilterParameters\<TAbi, TEventName, TArgs, TStrict, TFromBlock, TToBlock>) => Promise\<CreateContractEventFilterReturnType\<TAbi, TEventName, TArgs, TStrict, TFromBlock, TToBlock>>Creates a Filter to retrieve event logs that can be used with getFilterChanges or getFilterLogs. - Docs: https://viem.sh/docs/contract/createContractEventFilter Example ts import { createPublicClient, http, parseAbi } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const filter = await client.createContractEventFilter({ abi: parseAbi(['event Transfer(address indexed, address indexed, uint256)']), })
client.createEventFilter\<TAbiEvent, TAbiEvents, TStrict, TFromBlock, TToBlock, _EventName, _Args>(args?: CreateEventFilterParameters\<TAbiEvent, TAbiEvents, TStrict, TFromBlock, TToBlock, _EventName, _Args>) => Promise\<{ [K in string | number | symbol]: Filter\<"event", TAbiEvents, _EventName, _Args, TStrict, TFromBlock, TToBlock>[K] }>Creates a Filter to listen for new events that can be used with getFilterChanges. - Docs: https://viem.sh/docs/actions/public/createEventFilter - JSON-RPC Methods: eth_newFilter Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const filter = await client.createEventFilter({ address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2', })
client.createPendingTransactionFilter() => Promise\<{ id: `0x${string}` ; request: EIP1193RequestFn\<readonly [{ Method: "eth_getFilterChanges" ; Parameters: [filterId: `0x${string}`] ; ReturnType: `0x${string}`[] | RpcLog[] }, { Method: "eth_getFilterLogs" ; Parameters: [filterId: `0x${string}`] ; ReturnType: RpcLog[] }, { Method: "eth_uninstallFilter" ; Parameters: [filterId: `0x${string}`] ; ReturnType: boolean }]> ; type: "transaction" }>Creates a Filter to listen for new pending transaction hashes that can be used with getFilterChanges. - Docs: https://viem.sh/docs/actions/public/createPendingTransactionFilter - JSON-RPC Methods: eth_newPendingTransactionFilter Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const filter = await client.createPendingTransactionFilter() // { id: "0x345a6572337856574a76364e457a4366", type: 'transaction' }
client.estimateContractGas\<TChain, abi, functionName, args>(args: EstimateContractGasParameters\<abi, functionName, args, TChain>) => Promise\<bigint>Estimates the gas required to successfully execute a contract write function call. - Docs: https://viem.sh/docs/contract/estimateContractGas Remarks Internally, uses a Public Client to call the estimateGas action with ABI-encoded data. Example ts import { createPublicClient, http, parseAbi } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const gas = await client.estimateContractGas({ address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', abi: parseAbi(['function mint() public']), functionName: 'mint', account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', })
client.estimateFeesPerGas\<TChainOverride, TType>(args?: EstimateFeesPerGasParameters\<undefined | Chain, TChainOverride, TType>) => Promise\<EstimateFeesPerGasReturnType>Returns an estimate for the fees per gas for a transaction to be included in the next block. - Docs: https://viem.sh/docs/actions/public/estimateFeesPerGas Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const maxPriorityFeePerGas = await client.estimateFeesPerGas() // { maxFeePerGas: ..., maxPriorityFeePerGas: ... }
client.estimateGas(args: EstimateGasParameters\<undefined | Chain>) => Promise\<bigint>Estimates the gas necessary to complete a transaction without submitting it to the network. - Docs: https://viem.sh/docs/actions/public/estimateGas - JSON-RPC Methods: eth_estimateGas Example ts import { createPublicClient, http, parseEther } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const gasEstimate = await client.estimateGas({ account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: parseEther('1'), })
client.estimateMaxPriorityFeePerGas\<TChainOverride>(args?: { chain: null | TChainOverride }) => Promise\<bigint>Returns an estimate for the max priority fee per gas (in wei) for a transaction to be included in the next block. - Docs: https://viem.sh/docs/actions/public/estimateMaxPriorityFeePerGas Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const maxPriorityFeePerGas = await client.estimateMaxPriorityFeePerGas() // 10000000n
client.extend\<client>(fn: (client: Client\<Transport, undefined | Chain, undefined, PublicRpcSchema, PublicActions\<Transport, undefined | Chain>>) => client) => Client\<Transport, undefined | Chain, undefined, PublicRpcSchema, { [K in string | number | symbol]: client[K] } & PublicActions\<Transport, undefined | Chain>>-
client.getBalance(args: GetBalanceParameters) => Promise\<bigint>Returns the balance of an address in wei. - Docs: https://viem.sh/docs/actions/public/getBalance - JSON-RPC Methods: eth_getBalance Remarks You can convert the balance to ether units with formatEther. ts const balance = await getBalance(client, { address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', blockTag: 'safe' }) const balanceAsEther = formatEther(balance) // "6.942" Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const balance = await client.getBalance({ address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', }) // 10000000000000000000000n (wei)
client.getBlobBaseFee() => Promise\<bigint>Returns the base fee per blob gas in wei. - Docs: https://viem.sh/docs/actions/public/getBlobBaseFee - JSON-RPC Methods: eth_blobBaseFee Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' import { getBlobBaseFee } from 'viem/public' const client = createPublicClient({ chain: mainnet, transport: http(), }) const blobBaseFee = await client.getBlobBaseFee()
client.getBlock\<TIncludeTransactions, TBlockTag>(args?: GetBlockParameters\<TIncludeTransactions, TBlockTag>) => Promise\<{ baseFeePerGas: null | bigint ; blobGasUsed: bigint ; difficulty: bigint ; excessBlobGas: bigint ; extraData: `0x${string}` ; gasLimit: bigint ; gasUsed: bigint ; hash: TBlockTag extends "pending" ? null : `0x${string}` ; logsBloom: TBlockTag extends "pending" ? null : `0x${string}` ; miner: `0x${string}` ; mixHash: `0x${string}` ; nonce: TBlockTag extends "pending" ? null : `0x${string}` ; number: TBlockTag extends "pending" ? null : bigint ; parentHash: `0x${string}` ; receiptsRoot: `0x${string}` ; sealFields: `0x${string}`[] ; sha3Uncles: `0x${string}` ; size: bigint ; stateRoot: `0x${string}` ; timestamp: bigint ; totalDifficulty: null | bigint ; transactions: TIncludeTransactions extends true ? ({ accessList?: undefined ; blobVersionedHashes?: undefined ; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}` ; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint ; chainId?: number ; from: `0x${string}` ; gas: bigint ; gasPrice: bigint ; hash: `0x${string}` ; input: `0x${string}` ; maxFeePerBlobGas?: undefined ; maxFeePerGas?: undefined ; maxPriorityFeePerGas?: undefined ; nonce: number ; r: `0x${string}` ; s: `0x${string}` ; to: null | `0x${string}` ; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number ; type: "legacy" ; typeHex: null | `0x${string}` ; v: bigint ; value: bigint ; yParity?: undefined } | { accessList: AccessList ; blobVersionedHashes?: undefined ; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}` ; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint ; chainId: number ; from: `0x${string}` ; gas: bigint ; gasPrice: bigint ; hash: `0x${string}` ; input: `0x${string}` ; maxFeePerBlobGas?: undefined ; maxFeePerGas?: undefined ; maxPriorityFeePerGas?: undefined ; nonce: number ; r: `0x${string}` ; s: `0x${string}` ; to: null | `0x${string}` ; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number ; type: "eip2930" ; typeHex: null | `0x${string}` ; v: bigint ; value: bigint ; yParity: number } | { accessList: AccessList ; blobVersionedHashes?: undefined ; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}` ; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint ; chainId: number ; from: `0x${string}` ; gas: bigint ; gasPrice?: undefined ; hash: `0x${string}` ; input: `0x${string}` ; maxFeePerBlobGas?: undefined ; maxFeePerGas: bigint ; maxPriorityFeePerGas: bigint ; nonce: number ; r: `0x${string}` ; s: `0x${string}` ; to: null | `0x${string}` ; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number ; type: "eip1559" ; typeHex: null | `0x${string}` ; v: bigint ; value: bigint ; yParity: number } | { accessList: AccessList ; blobVersionedHashes: `0x${string}`[] ; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}` ; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint ; chainId: number ; from: `0x${string}` ; gas: bigint ; gasPrice?: undefined ; hash: `0x${string}` ; input: `0x${string}` ; maxFeePerBlobGas: bigint ; maxFeePerGas: bigint ; maxPriorityFeePerGas: bigint ; nonce: number ; r: `0x${string}` ; s: `0x${string}` ; to: null | `0x${string}` ; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number ; type: "eip4844" ; typeHex: null | `0x${string}` ; v: bigint ; value: bigint ; yParity: number })[] : `0x${string}`[] ; transactionsRoot: `0x${string}` ; uncles: `0x${string}`[] ; withdrawals?: Withdrawal[] ; withdrawalsRoot?: `0x${string}` }>Returns information about a block at a block number, hash, or tag. - Docs: https://viem.sh/docs/actions/public/getBlock - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks/fetching-blocks - JSON-RPC Methods: - Calls eth_getBlockByNumber for blockNumber & blockTag. - Calls eth_getBlockByHash for blockHash. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const block = await client.getBlock()
client.getBlockNumber(args?: GetBlockNumberParameters) => Promise\<bigint>Returns the number of the most recent block seen. - Docs: https://viem.sh/docs/actions/public/getBlockNumber - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks/fetching-blocks - JSON-RPC Methods: eth_blockNumber Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const blockNumber = await client.getBlockNumber() // 69420n
client.getBlockTransactionCount(args?: GetBlockTransactionCountParameters) => Promise\<number>Returns the number of Transactions at a block number, hash, or tag. - Docs: https://viem.sh/docs/actions/public/getBlockTransactionCount - JSON-RPC Methods: - Calls eth_getBlockTransactionCountByNumber for blockNumber & blockTag. - Calls eth_getBlockTransactionCountByHash for blockHash. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const count = await client.getBlockTransactionCount()
client.getBytecode(args: GetBytecodeParameters) => Promise\<GetBytecodeReturnType>Retrieves the bytecode at an address. - Docs: https://viem.sh/docs/contract/getBytecode - JSON-RPC Methods: eth_getCode Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const code = await client.getBytecode({ address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', })
client.getChainId() => Promise\<number>Returns the chain ID associated with the current network. - Docs: https://viem.sh/docs/actions/public/getChainId - JSON-RPC Methods: eth_chainId Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const chainId = await client.getChainId() // 1
client.getContractEvents\<abi, eventName, strict, fromBlock, toBlock>(args: GetContractEventsParameters\<abi, eventName, strict, fromBlock, toBlock>) => Promise\<GetContractEventsReturnType\<abi, eventName, strict, fromBlock, toBlock>>Returns a list of event logs emitted by a contract. - Docs: https://viem.sh/docs/actions/public/getContractEvents - JSON-RPC Methods: eth_getLogs Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' import { wagmiAbi } from './abi' const client = createPublicClient({ chain: mainnet, transport: http(), }) const logs = await client.getContractEvents(client, { address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', abi: wagmiAbi, eventName: 'Transfer' })
client.getEnsAddress(args: { blockNumber?: bigint ; blockTag?: BlockTag ; coinType?: number ; gatewayUrls?: string[] ; name: string ; strict?: boolean ; universalResolverAddress?: `0x${string}` }) => Promise\<GetEnsAddressReturnType>Gets address for ENS name. - Docs: https://viem.sh/docs/ens/actions/getEnsAddress - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens Remarks Calls resolve(bytes, bytes) on ENS Universal Resolver Contract. Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to getEnsAddress. You can use the built-in normalize function for this. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' import { normalize } from 'viem/ens' const client = createPublicClient({ chain: mainnet, transport: http(), }) const ensAddress = await client.getEnsAddress({ name: normalize('wevm.eth'), }) // '0xd2135CfB216b74109775236E36d4b433F1DF507B'
client.getEnsAvatar(args: { assetGatewayUrls?: AssetGatewayUrls ; blockNumber?: bigint ; blockTag?: BlockTag ; gatewayUrls?: string[] ; name: string ; strict?: boolean ; universalResolverAddress?: `0x${string}` }) => Promise\<GetEnsAvatarReturnType>Gets the avatar of an ENS name. - Docs: https://viem.sh/docs/ens/actions/getEnsAvatar - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens Remarks Calls getEnsText with key set to 'avatar'. Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to getEnsAddress. You can use the built-in normalize function for this. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' import { normalize } from 'viem/ens' const client = createPublicClient({ chain: mainnet, transport: http(), }) const ensAvatar = await client.getEnsAvatar({ name: normalize('wevm.eth'), }) // 'https://ipfs.io/ipfs/Qma8mnp6xV3J2cRNf3mTth5C8nV11CAnceVinc3y8jSbio'
client.getEnsName(args: { address: `0x${string}` ; blockNumber?: bigint ; blockTag?: BlockTag ; gatewayUrls?: string[] ; strict?: boolean ; universalResolverAddress?: `0x${string}` }) => Promise\<GetEnsNameReturnType>Gets primary name for specified address. - Docs: https://viem.sh/docs/ens/actions/getEnsName - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens Remarks Calls reverse(bytes) on ENS Universal Resolver Contract to "reverse resolve" the address to the primary ENS name. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const ensName = await client.getEnsName({ address: '0xd2135CfB216b74109775236E36d4b433F1DF507B', }) // 'wevm.eth'
client.getEnsResolver(args: { blockNumber?: bigint ; blockTag?: BlockTag ; name: string ; universalResolverAddress?: `0x${string}` }) => Promise\<`0x${string}`>Gets resolver for ENS name. - Docs: https://viem.sh/docs/ens/actions/getEnsResolver - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens Remarks Calls findResolver(bytes) on ENS Universal Resolver Contract to retrieve the resolver of an ENS name. Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to getEnsAddress. You can use the built-in normalize function for this. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' import { normalize } from 'viem/ens' const client = createPublicClient({ chain: mainnet, transport: http(), }) const resolverAddress = await client.getEnsResolver({ name: normalize('wevm.eth'), }) // '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41'
client.getEnsText(args: { blockNumber?: bigint ; blockTag?: BlockTag ; gatewayUrls?: string[] ; key: string ; name: string ; strict?: boolean ; universalResolverAddress?: `0x${string}` }) => Promise\<GetEnsTextReturnType>Gets a text record for specified ENS name. - Docs: https://viem.sh/docs/ens/actions/getEnsResolver - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens Remarks Calls resolve(bytes, bytes) on ENS Universal Resolver Contract. Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to normalize ENS names with UTS-46 normalization before passing them to getEnsAddress. You can use the built-in normalize function for this. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' import { normalize } from 'viem/ens' const client = createPublicClient({ chain: mainnet, transport: http(), }) const twitterRecord = await client.getEnsText({ name: normalize('wevm.eth'), key: 'com.twitter', }) // 'wagmi_sh'
client.getFeeHistory(args: GetFeeHistoryParameters) => Promise\<GetFeeHistoryReturnType>Returns a collection of historical gas information. - Docs: https://viem.sh/docs/actions/public/getFeeHistory - JSON-RPC Methods: eth_feeHistory Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const feeHistory = await client.getFeeHistory({ blockCount: 4, rewardPercentiles: [25, 75], })
client.getFilterChanges\<TFilterType, TAbi, TEventName, TStrict, TFromBlock, TToBlock>(args: GetFilterChangesParameters\<TFilterType, TAbi, TEventName, TStrict, TFromBlock, TToBlock>) => Promise\<GetFilterChangesReturnType\<TFilterType, TAbi, TEventName, TStrict, TFromBlock, TToBlock>>Returns a list of logs or hashes based on a Filter since the last time it was called. - Docs: https://viem.sh/docs/actions/public/getFilterChanges - JSON-RPC Methods: eth_getFilterChanges Remarks A Filter can be created from the following actions: - createBlockFilter - createContractEventFilter - createEventFilter - createPendingTransactionFilter Depending on the type of filter, the return value will be different: - If the filter was created with createContractEventFilter or createEventFilter, it returns a list of logs. - If the filter was created with createPendingTransactionFilter, it returns a list of transaction hashes. - If the filter was created with createBlockFilter, it returns a list of block hashes. Example ts // Blocks import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const filter = await client.createBlockFilter() const hashes = await client.getFilterChanges({ filter }) Example ts // Contract Events import { createPublicClient, http, parseAbi } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const filter = await client.createContractEventFilter({ address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', abi: parseAbi(['event Transfer(address indexed, address indexed, uint256)']), eventName: 'Transfer', }) const logs = await client.getFilterChanges({ filter }) Example ts // Raw Events import { createPublicClient, http, parseAbiItem } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const filter = await client.createEventFilter({ address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', event: parseAbiItem('event Transfer(address indexed, address indexed, uint256)'), }) const logs = await client.getFilterChanges({ filter }) Example ts // Transactions import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const filter = await client.createPendingTransactionFilter() const hashes = await client.getFilterChanges({ filter })
client.getFilterLogs\<TAbi, TEventName, TStrict, TFromBlock, TToBlock>(args: GetFilterLogsParameters\<TAbi, TEventName, TStrict, TFromBlock, TToBlock>) => Promise\<GetFilterLogsReturnType\<TAbi, TEventName, TStrict, TFromBlock, TToBlock>>Returns a list of event logs since the filter was created. - Docs: https://viem.sh/docs/actions/public/getFilterLogs - JSON-RPC Methods: eth_getFilterLogs Remarks getFilterLogs is only compatible with event filters. Example ts import { createPublicClient, http, parseAbiItem } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const filter = await client.createEventFilter({ address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', event: parseAbiItem('event Transfer(address indexed, address indexed, uint256)'), }) const logs = await client.getFilterLogs({ filter })
client.getGasPrice() => Promise\<bigint>Returns the current price of gas (in wei). - Docs: https://viem.sh/docs/actions/public/getGasPrice - JSON-RPC Methods: eth_gasPrice Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const gasPrice = await client.getGasPrice()
client.getLogs\<TAbiEvent, TAbiEvents, TStrict, TFromBlock, TToBlock>(args?: GetLogsParameters\<TAbiEvent, TAbiEvents, TStrict, TFromBlock, TToBlock>) => Promise\<GetLogsReturnType\<TAbiEvent, TAbiEvents, TStrict, TFromBlock, TToBlock>>Returns a list of event logs matching the provided parameters. - Docs: https://viem.sh/docs/actions/public/getLogs - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/filters-and-logs/event-logs - JSON-RPC Methods: eth_getLogs Example ts import { createPublicClient, http, parseAbiItem } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const logs = await client.getLogs()
client.getProof(args: GetProofParameters) => Promise\<GetProofReturnType>Returns the account and storage values of the specified account including the Merkle-proof. - Docs: https://viem.sh/docs/actions/public/getProof - JSON-RPC Methods: - Calls eth_getProof Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const block = await client.getProof({ address: '0x...', storageKeys: ['0x...'], })
client.getStorageAt(args: GetStorageAtParameters) => Promise\<GetStorageAtReturnType>Returns the value from a storage slot at a given address. - Docs: https://viem.sh/docs/contract/getStorageAt - JSON-RPC Methods: eth_getStorageAt Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' import { getStorageAt } from 'viem/contract' const client = createPublicClient({ chain: mainnet, transport: http(), }) const code = await client.getStorageAt({ address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', slot: toHex(0), })
client.getTransaction\<TBlockTag>(args: GetTransactionParameters\<TBlockTag>) => Promise\<{ accessList?: undefined ; blobVersionedHashes?: undefined ; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}` ; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint ; chainId?: number ; from: `0x${string}` ; gas: bigint ; gasPrice: bigint ; hash: `0x${string}` ; input: `0x${string}` ; maxFeePerBlobGas?: undefined ; maxFeePerGas?: undefined ; maxPriorityFeePerGas?: undefined ; nonce: number ; r: `0x${string}` ; s: `0x${string}` ; to: null | `0x${string}` ; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number ; type: "legacy" ; typeHex: null | `0x${string}` ; v: bigint ; value: bigint ; yParity?: undefined } | { accessList: AccessList ; blobVersionedHashes?: undefined ; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}` ; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint ; chainId: number ; from: `0x${string}` ; gas: bigint ; gasPrice: bigint ; hash: `0x${string}` ; input: `0x${string}` ; maxFeePerBlobGas?: undefined ; maxFeePerGas?: undefined ; maxPriorityFeePerGas?: undefined ; nonce: number ; r: `0x${string}` ; s: `0x${string}` ; to: null | `0x${string}` ; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number ; type: "eip2930" ; typeHex: null | `0x${string}` ; v: bigint ; value: bigint ; yParity: number } | { accessList: AccessList ; blobVersionedHashes?: undefined ; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}` ; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint ; chainId: number ; from: `0x${string}` ; gas: bigint ; gasPrice?: undefined ; hash: `0x${string}` ; input: `0x${string}` ; maxFeePerBlobGas?: undefined ; maxFeePerGas: bigint ; maxPriorityFeePerGas: bigint ; nonce: number ; r: `0x${string}` ; s: `0x${string}` ; to: null | `0x${string}` ; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number ; type: "eip1559" ; typeHex: null | `0x${string}` ; v: bigint ; value: bigint ; yParity: number } | { accessList: AccessList ; blobVersionedHashes: `0x${string}`[] ; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}` ; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint ; chainId: number ; from: `0x${string}` ; gas: bigint ; gasPrice?: undefined ; hash: `0x${string}` ; input: `0x${string}` ; maxFeePerBlobGas: bigint ; maxFeePerGas: bigint ; maxPriorityFeePerGas: bigint ; nonce: number ; r: `0x${string}` ; s: `0x${string}` ; to: null | `0x${string}` ; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number ; type: "eip4844" ; typeHex: null | `0x${string}` ; v: bigint ; value: bigint ; yParity: number }>Returns information about a Transaction given a hash or block identifier. - Docs: https://viem.sh/docs/actions/public/getTransaction - Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions/fetching-transactions - JSON-RPC Methods: eth_getTransactionByHash Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const transaction = await client.getTransaction({ hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', })
client.getTransactionConfirmations(args: GetTransactionConfirmationsParameters\<undefined | Chain>) => Promise\<bigint>Returns the number of blocks passed (confirmations) since the transaction was processed on a block. - Docs: https://viem.sh/docs/actions/public/getTransactionConfirmations - Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions/fetching-transactions - JSON-RPC Methods: eth_getTransactionConfirmations Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const confirmations = await client.getTransactionConfirmations({ hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', })
client.getTransactionCount(args: GetTransactionCountParameters) => Promise\<number>Returns the number of Transactions an Account has broadcast / sent. - Docs: https://viem.sh/docs/actions/public/getTransactionCount - JSON-RPC Methods: eth_getTransactionCount Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const transactionCount = await client.getTransactionCount({ address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', })
client.getTransactionReceipt(args: GetTransactionReceiptParameters) => Promise\<TransactionReceipt>Returns the Transaction Receipt given a Transaction hash. - Docs: https://viem.sh/docs/actions/public/getTransactionReceipt - Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions/fetching-transactions - JSON-RPC Methods: eth_getTransactionReceipt Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const transactionReceipt = await client.getTransactionReceipt({ hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', })
client.keystringA key for the client.
client.multicall\<contracts, allowFailure>(args: MulticallParameters\<contracts, allowFailure>) => Promise\<MulticallReturnType\<contracts, allowFailure>>Similar to readContract, but batches up multiple functions on a contract in a single RPC call via the multicall3 contract. - Docs: https://viem.sh/docs/contract/multicall Example ts import { createPublicClient, http, parseAbi } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const abi = parseAbi([ 'function balanceOf(address) view returns (uint256)', 'function totalSupply() view returns (uint256)', ]) const result = await client.multicall({ contracts: [ { address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', abi, functionName: 'balanceOf', args: ['0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'], }, { address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', abi, functionName: 'totalSupply', }, ], }) // [{ result: 424122n, status: 'success' }, { result: 1000000n, status: 'success' }]
client.namestringA name for the client.
client.pollingIntervalnumberFrequency (in ms) for polling enabled actions & events. Defaults to 4_000 milliseconds.
client.prepareTransactionRequest\<TRequest, TChainOverride, TAccountOverride>(args: PrepareTransactionRequestParameters\<undefined | Chain, undefined | Account, TChainOverride, TAccountOverride, TRequest>) => Promise\<{ [K in string | number | symbol]: (UnionRequiredBy\<Extract\<UnionOmit\<(...), (...)> & ((...) extends (...) ? (...) : (...)) & ((...) extends (...) ? (...) : (...)), IsNever\<(...)> extends true ? unknown : ExactPartial\<(...)>> & Object, ParameterTypeToParameters\<TRequest["parameters"] extends readonly PrepareTransactionRequestParameterType[] ? any[any][number] : "type" | "gas" | "nonce" | "blobVersionedHashes" | "chainId" | "fees">> & (unknown extends TRequest["kzg"] ? Object : Pick\<TRequest, "kzg">))[K] }>Prepares a transaction request for signing. - Docs: https://viem.sh/docs/actions/wallet/prepareTransactionRequest Example ts import { createWalletClient, custom } from 'viem' import { mainnet } from 'viem/chains' const client = createWalletClient({ chain: mainnet, transport: custom(window.ethereum), }) const request = await client.prepareTransactionRequest({ account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', to: '0x0000000000000000000000000000000000000000', value: 1n, }) Example ts // Account Hoisting import { createWalletClient, http } from 'viem' import { privateKeyToAccount } from 'viem/accounts' import { mainnet } from 'viem/chains' const client = createWalletClient({ account: privateKeyToAccount('0x…'), chain: mainnet, transport: custom(window.ethereum), }) const request = await client.prepareTransactionRequest({ to: '0x0000000000000000000000000000000000000000', value: 1n, })
client.readContract\<abi, functionName, args>(args: ReadContractParameters\<abi, functionName, args>) => Promise\<ReadContractReturnType\<abi, functionName, args>>Calls a read-only function on a contract, and returns the response. - Docs: https://viem.sh/docs/contract/readContract - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/contracts/reading-contracts Remarks A "read-only" function (constant function) on a Solidity contract is denoted by a view or pure keyword. They can only read the state of the contract, and cannot make any changes to it. Since read-only methods do not change the state of the contract, they do not require any gas to be executed, and can be called by any user without the need to pay for gas. Internally, uses a Public Client to call the call action with ABI-encoded data. Example ts import { createPublicClient, http, parseAbi } from 'viem' import { mainnet } from 'viem/chains' import { readContract } from 'viem/contract' const client = createPublicClient({ chain: mainnet, transport: http(), }) const result = await client.readContract({ address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', abi: parseAbi(['function balanceOf(address) view returns (uint256)']), functionName: 'balanceOf', args: ['0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'], }) // 424122n
client.requestEIP1193RequestFn\<PublicRpcSchema>Request function wrapped with friendly error handling
client.sendRawTransaction(args: SendRawTransactionParameters) => Promise\<`0x${string}`>Sends a signed transaction to the network - Docs: https://viem.sh/docs/actions/wallet/sendRawTransaction - JSON-RPC Method: eth_sendRawTransaction Example ts import { createWalletClient, custom } from 'viem' import { mainnet } from 'viem/chains' import { sendRawTransaction } from 'viem/wallet' const client = createWalletClient({ chain: mainnet, transport: custom(window.ethereum), }) const hash = await client.sendRawTransaction({ serializedTransaction: '0x02f850018203118080825208808080c080a04012522854168b27e5dc3d5839bab5e6b39e1a0ffd343901ce1622e3d64b48f1a04e00902ae0502c4728cbf12156290df99c3ed7de85b1dbfe20b5c36931733a33' })
client.simulateContract\<abi, functionName, args, chainOverride, accountOverride>(args: SimulateContractParameters\<abi, functionName, args, undefined | Chain, chainOverride, accountOverride>) => Promise\<SimulateContractReturnType\<abi, functionName, args, undefined | Chain, undefined | Account, chainOverride, accountOverride>>Simulates/validates a contract interaction. This is useful for retrieving return data and revert reasons of contract write functions. - Docs: https://viem.sh/docs/contract/simulateContract - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/contracts/writing-to-contracts Remarks This function does not require gas to execute and does not change the state of the blockchain. It is almost identical to readContract, but also supports contract write functions. Internally, uses a Public Client to call the call action with ABI-encoded data. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const result = await client.simulateContract({ address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', abi: parseAbi(['function mint(uint32) view returns (uint32)']), functionName: 'mint', args: ['69420'], account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', })
client.transportTransportConfig\<string, EIP1193RequestFn> & Record\<string, any>The RPC transport
client.typestringThe type of client.
client.uidstringA unique ID for the client.
client.uninstallFilter(args: UninstallFilterParameters) => Promise\<boolean>Destroys a Filter that was created from one of the following Actions: - createBlockFilter - createEventFilter - createPendingTransactionFilter - Docs: https://viem.sh/docs/actions/public/uninstallFilter - JSON-RPC Methods: eth_uninstallFilter Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' import { createPendingTransactionFilter, uninstallFilter } from 'viem/public' const filter = await client.createPendingTransactionFilter() const uninstalled = await client.uninstallFilter({ filter }) // true
client.verifyMessage(args: VerifyMessageParameters) => Promise\<boolean>-
client.verifyTypedData(args: VerifyTypedDataParameters) => Promise\<boolean>-
client.waitForTransactionReceipt(args: WaitForTransactionReceiptParameters\<undefined | Chain>) => Promise\<TransactionReceipt>Waits for the Transaction to be included on a Block (one confirmation), and then returns the Transaction Receipt. If the Transaction reverts, then the action will throw an error. - Docs: https://viem.sh/docs/actions/public/waitForTransactionReceipt - Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions/sending-transactions - JSON-RPC Methods: - Polls eth_getTransactionReceipt on each block until it has been processed. - If a Transaction has been replaced: - Calls eth_getBlockByNumber and extracts the transactions - Checks if one of the Transactions is a replacement - If so, calls eth_getTransactionReceipt. Remarks The waitForTransactionReceipt action additionally supports Replacement detection (e.g. sped up Transactions). Transactions can be replaced when a user modifies their transaction in their wallet (to speed up or cancel). Transactions are replaced when they are sent from the same nonce. There are 3 types of Transaction Replacement reasons: - repriced: The gas price has been modified (e.g. different maxFeePerGas) - cancelled: The Transaction has been cancelled (e.g. value === 0n) - replaced: The Transaction has been replaced (e.g. different value or data) Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const transactionReceipt = await client.waitForTransactionReceipt({ hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d', })
client.watchBlockNumber(args: WatchBlockNumberParameters) => WatchBlockNumberReturnTypeWatches and returns incoming block numbers. - Docs: https://viem.sh/docs/actions/public/watchBlockNumber - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks/watching-blocks - JSON-RPC Methods: - When poll: true, calls eth_blockNumber on a polling interval. - When poll: false & WebSocket Transport, uses a WebSocket subscription via eth_subscribe and the "newHeads" event. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const unwatch = await client.watchBlockNumber({ onBlockNumber: (blockNumber) => console.log(blockNumber), })
client.watchBlocks\<TIncludeTransactions, TBlockTag>(args: WatchBlocksParameters\<Transport, undefined | Chain, TIncludeTransactions, TBlockTag>) => WatchBlocksReturnTypeWatches and returns information for incoming blocks. - Docs: https://viem.sh/docs/actions/public/watchBlocks - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks/watching-blocks - JSON-RPC Methods: - When poll: true, calls eth_getBlockByNumber on a polling interval. - When poll: false & WebSocket Transport, uses a WebSocket subscription via eth_subscribe and the "newHeads" event. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const unwatch = await client.watchBlocks({ onBlock: (block) => console.log(block), })
client.watchContractEvent\<TAbi, TEventName, TStrict>(args: WatchContractEventParameters\<TAbi, TEventName, TStrict, Transport>) => WatchContractEventReturnTypeWatches and returns emitted contract event logs. - Docs: https://viem.sh/docs/contract/watchContractEvent Remarks This Action will batch up all the event logs found within the pollingInterval, and invoke them via onLogs. watchContractEvent will attempt to create an Event Filter and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. eth_newFilter), then watchContractEvent will fall back to using getLogs instead. Example ts import { createPublicClient, http, parseAbi } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const unwatch = client.watchContractEvent({ address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', abi: parseAbi(['event Transfer(address indexed from, address indexed to, uint256 value)']), eventName: 'Transfer', args: { from: '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b' }, onLogs: (logs) => console.log(logs), })
client.watchEvent\<TAbiEvent, TAbiEvents, TStrict>(args: WatchEventParameters\<TAbiEvent, TAbiEvents, TStrict, Transport>) => WatchEventReturnTypeWatches and returns emitted Event Logs. - Docs: https://viem.sh/docs/actions/public/watchEvent - JSON-RPC Methods: - RPC Provider supports eth_newFilter: - Calls eth_newFilter to create a filter (called on initialize). - On a polling interval, it will call eth_getFilterChanges. - RPC Provider does not support eth_newFilter: - Calls eth_getLogs for each block between the polling interval. Remarks This Action will batch up all the Event Logs found within the pollingInterval, and invoke them via onLogs. watchEvent will attempt to create an Event Filter and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. eth_newFilter), then watchEvent will fall back to using getLogs instead. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const unwatch = client.watchEvent({ onLogs: (logs) => console.log(logs), })
client.watchPendingTransactions(args: WatchPendingTransactionsParameters\<Transport>) => WatchPendingTransactionsReturnTypeWatches and returns pending transaction hashes. - Docs: https://viem.sh/docs/actions/public/watchPendingTransactions - JSON-RPC Methods: - When poll: true - Calls eth_newPendingTransactionFilter to initialize the filter. - Calls eth_getFilterChanges on a polling interval. - When poll: false & WebSocket Transport, uses a WebSocket subscription via eth_subscribe and the "newPendingTransactions" event. Remarks This Action will batch up all the pending transactions found within the pollingInterval, and invoke them via onTransactions. Example ts import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' const client = createPublicClient({ chain: mainnet, transport: http(), }) const unwatch = await client.watchPendingTransactions({ onTransactions: (hashes) => console.log(hashes), })

Returns

Promise\<boolean>

true if the contract exists and false otherwise

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:213


createKernelClient

createKernelClient(signer, chainId, zeroDevProjectId): Promise\<KernelAccountClient\<"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", Transport, Chain, any>>

It creates a ZeroDev Kernel client.

Parameters

NameTypeDescription
signeranythe signer account
chainIdnumberthe chain id
zeroDevProjectIdstringthe zero dev project id, you can get it from the ZeroDev dashboard

Returns

Promise\<KernelAccountClient\<"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", Transport, Chain, any>>

the kernel client

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:533


createSessionKey

createSessionKey(signer, publicClient, permissions): Promise\<string>

It creates a ZeroDev Session Key with some specific permissions

Parameters

NameTypeDescription
signeranythe signer account
publicClientanythe blockchain client
permissionsany[]the permissions to configure in the session key

Returns

Promise\<string>

the session key serialized

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:581


decryptMessage

decryptMessage(encryptedMessage, privateKey): Promise\<string>

Parameters

NameType
encryptedMessagestring
privateKeyany

Returns

Promise\<string>

Defined in

src/common/helpers.ts:81


deployContractInstance

deployContractInstance(artifact, from, args?, client): Promise\<{ abi: Abi ; address: `0x${string}` ; createEventFilter: {} ; estimateGas: {} & {} ; getEvents: {} ; read: {} ; simulate: {} ; watchEvent: {} ; write: {} }>

Given an artifact, it deploys the contract and returns the contract instance.

Parameters

NameTypeDefault valueDescription
artifactObjectundefinedthe contract artifact
artifact.abiAbiundefined-
artifact.bytecode`0x${string}`undefined-
artifact.name?stringundefined-
fromNvmAccountundefinedthe deployer account
argsstring[][]parameters to be passed to the contract during the initialization
clientWeb3Clientsundefinedthe client to interact with the blockchain

Returns

Promise\<{ abi: Abi ; address: `0x${string}` ; createEventFilter: {} ; estimateGas: {} & {} ; getEvents: {} ; read: {} ; simulate: {} ; watchEvent: {} ; write: {} }>

a contract instance

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:150


deserializeECIES

deserializeECIES(serialized): Object

Parameters

NameType
serializedany

Returns

Object

NameType
ciphertextBuffer
ephemPublicKeyBuffer
ivBuffer
macBuffer

Defined in

src/common/helpers.ts:98


didPrefixed

didPrefixed(input): string

Parameters

NameType
inputstring

Returns

string

Defined in

src/utils/ConversionTypeHelpers.ts:13


didToTokenId

didToTokenId(did): bigint

It converts a DID to a Token ID. This is useful because in the Solidity Smart contracts the tokenId is a uint256.

Parameters

NameTypeDescription
didstringthe unique identifier of the asset

Returns

bigint

the token id in a bigint format

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:320


didTransformer

didTransformer(input?, prefixOutput): string

Parameters

NameTypeDefault value
inputstring''
prefixOutputbooleanundefined

Returns

string

Defined in

src/utils/ConversionTypeHelpers.ts:16


didZeroX

didZeroX(input): `0x${string}`

Parameters

NameType
inputstring

Returns

`0x${string}`

Defined in

src/utils/ConversionTypeHelpers.ts:22


encodeBytes32String

encodeBytes32String(message): `0x${string}`

Encodes a UTF-8 string into a hex string

Parameters

NameTypeDescription
messagestringthe string to encode

Returns

`0x${string}`

the hex string

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:367


encryptMessage

encryptMessage(message, receiverPublicKey): Promise\<string>

Parameters

NameType
messagestring
receiverPublicKeystring

Returns

Promise\<string>

Defined in

src/common/helpers.ts:74


eventToObject

eventToObject(event): any

Parameters

NameType
eventany

Returns

any

Defined in

src/utils/Events.ts:1


formatEther

formatEther(value): string

Converts a wei value into ether.

Parameters

NameTypeDescription
valuebigintThe value to format.

Returns

string

The string of the formatted value

Example

const value = 1000000000000000000n

formatEther(value)
// '1.0'

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:520


formatUnits

formatUnits(value, decimals?): string

Returns a string representation of value formatted with decimal digits.

Parameters

NameTypeDefault valueDescription
valuebigintundefinedThe value to format.
decimalsnumber18-

Returns

string

The string of the formatted value

Example

const oneEther = 1000000000000000000n

formatUnits(oneEther, 18)
// '1.0'

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:483


generateId

generateId(length?): string

Parameters

NameTypeDefault value
lengthnumber64

Returns

string

Defined in

src/common/helpers.ts:39


generateInstantiableConfigFromConfig

generateInstantiableConfigFromConfig(config, loadCore?): Promise\<Partial\<InstantiableConfig>>

Parameters

NameTypeDefault value
configNeverminedOptionsundefined
loadCorebooleantrue

Returns

Promise\<Partial\<InstantiableConfig>>

Defined in

src/Instantiable.abstract.ts:30


getBytes

getBytes(message): Uint8Array

Encodes a UTF-8 string into a byte array.

Parameters

NameTypeDescription
messagestringthe string to encode

Returns

Uint8Array

the encoded byte array

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:348


getChain

getChain(networkId): Chain

Parameters

NameType
networkIdundefined | number

Returns

Chain

Defined in

src/utils/Network.ts:148


getChecksumAddress

getChecksumAddress(address): string

Given an address it returns that address in checksum format.

Parameters

NameTypeDescription
addressstringthe address

Returns

string

the same address in checksum format

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:329


getCircularReplacer

getCircularReplacer(): (_key: any, value: any) => any

Returns

fn

▸ (_key, value): any

Parameters
NameType
_keyany
valueany
Returns

any

Defined in

src/common/helpers.ts:21


getConditionsByParams

getConditionsByParams(serviceType, conditions, owner, assetPrice?, did?, erc20TokenContract?, nftTokenContract?, nftHolder?, nftAmount?, nftTransfer?, duration?, fulfillAccessTimeout?, fulfillAccessTimelock?, tokenId?): ServiceAgreementTemplateCondition[]

Fill some static parameters that depends on the metadata.

Parameters

NameTypeDefault valueDescription
serviceTypeServiceTypeundefinedThe type of the service "access", "nft-sales", etc.
conditionsreadonly ServiceAgreementTemplateCondition[]undefinedList of conditions to fill.
ownerstringundefinedOwner of the asset.
assetPriceAssetPriceundefinedRewards distribution
did?stringundefinedThe DID of the asset.
erc20TokenContract?stringundefinedThe address of the ERC20 token contract used for payment (0x0 address if native token).
nftTokenContract?stringundefinedThe address of the NFT token contract used.
nftHolder?stringundefinedThe address of the NFT holder.
nftAmountbigintundefinedNumber of nfts to handle
nftTransferbooleanfalseIf the nft will be transferred (true) or minted (false)
durationnumber0Duration if it's a subscription
fulfillAccessTimeoutnumber0Timeout for the fulfill of the access service
fulfillAccessTimelocknumber0Timelock for the fulfill of the access service
tokenIdstring''The token id of the NFT

Returns

ServiceAgreementTemplateCondition[]

Filled conditions.

Defined in

src/ddo/DDO.ts:58


getContractInstance

getContractInstance(contractAddress, abi, client): Promise\<{ abi: Abi ; address: `0x${string}` ; createEventFilter: {} ; estimateGas: {} & {} ; getEvents: {} ; read: {} ; simulate: {} ; watchEvent: {} ; write: {} }>

Given an already deployed contract address and the ABI, it returns the contract instance.

Parameters

NameTypeDescription
contractAddressstringthe contract address
abiAbithe contract artifact
clientWeb3Clientsthe client to interact with the blockchain

Returns

Promise\<{ abi: Abi ; address: `0x${string}` ; createEventFilter: {} ; estimateGas: {} & {} ; getEvents: {} ; read: {} ; simulate: {} ; watchEvent: {} ; write: {} }>

a contract instance

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:199


getInputsOfFunction

getInputsOfFunction(abi, funcName, args?): readonly AbiParameter[]

It searchs an ABI function in the ABI and return the inputs.

Parameters

NameTypeDefault valueDescription
abiAbiundefinedthe ABI of the contract
funcNamestringundefinedthe function name
argsany[][]the args of the function

Returns

readonly AbiParameter[]

the function found

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:292


getInputsOfFunctionFormatted

getInputsOfFunctionFormatted(abi, funcName, args?): { name: undefined | string = input.name; value: any }[]

It searchs an ABI function in the ABI and return the inputs formatted.

Parameters

NameTypeDefault valueDescription
abiAbiundefinedthe ABI of the contract
funcNamestringundefinedthe function name
argsany[][]the args of the function

Returns

{ name: undefined | string = input.name; value: any }[]

the function found

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:303


getNetworkName

getNetworkName(networkId): Promise\<string>

Parameters

NameType
networkIdnumber

Returns

Promise\<string>

Defined in

src/utils/Network.ts:19


getRoyaltyAttributes

getRoyaltyAttributes(nvm, kind, amount): RoyaltyAttributes

It gets a RoyaltyAttributes instance

Parameters

NameTypeDescription
nvmNeverminedNevermined instance
kindRoyaltyKindThe type of royalty
amountnumberThe amount of royalties to get in the secondary market

Returns

RoyaltyAttributes

The RoyaltyAttributes instance

Defined in

src/nevermined/api/AssetsApi.ts:62


getRoyaltyScheme

getRoyaltyScheme(nvm, kind): RoyaltyScheme | undefined

It gets the on-chain royalties scheme

Parameters

NameTypeDescription
nvmNeverminedNevermined instance
kindRoyaltyKindThe type of royalty

Returns

RoyaltyScheme | undefined

The royalty scheme

Defined in

src/nevermined/api/AssetsApi.ts:47


getSessionKey

getSessionKey(serializedSessionKey, zeroDevProjectId, publicClient): Promise\<NvmAccount>

Given a serialized session key it reconstructs the NvmAccount represented by the session key.

Parameters

NameTypeDescription
serializedSessionKeystringthe serialized session key
zeroDevProjectIdstringthe zero dev project id
publicClientanythe blockchain client

Returns

Promise\<NvmAccount>

the NvmAccount represented by the session key

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:616


getSignatureOfFunction

getSignatureOfFunction(abi, funcName, args?): AbiFunction

It searchs an ABI function in the ABI.

Parameters

NameTypeDefault valueDescription
abiAbiundefinedthe ABI of the contract
funcNamestringundefinedthe function name
argsany[][]the args of the function

Returns

AbiFunction

the function found

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:281


getWeb3ViemClients

getWeb3ViemClients(config?): Promise\<Web3Clients>

Parameters

NameType
configPartial\<NeverminedOptions>

Returns

Promise\<Web3Clients>

Defined in

src/Instantiable.abstract.ts:50


isTestnet

isTestnet(networkId): boolean

Parameters

NameType
networkIdnumber

Returns

boolean

Defined in

src/utils/Network.ts:83


isValidAddress

isValidAddress(address): boolean

It checks if the address is a valid address.

Parameters

NameTypeDescription
addressstringthe address to check

Returns

boolean

true of the address is valid

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:338


jsonReplacer

jsonReplacer(_key, value): any

Parameters

NameType
_keyany
valueany

Returns

any

Defined in

src/common/helpers.ts:34


keccak256

keccak256(seed): string

It hashes a string using keccak256.

Parameters

NameTypeDescription
seedstringthe string to hash

Returns

string

the hash

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:422


keccak256Packed

keccak256Packed(types, values): string

It encodes and hashes a list of primitive values into an ABI-encoded hex value.

Parameters

NameTypeDescription
typesany[]the types of the values
valuesany[]the values to encode

Returns

string

the hash

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:443


keccak256WithEncode

keccak256WithEncode(types, values): string

It encodes and hashes a list of primitive values into an ABI-encoded hex value.

Parameters

NameTypeDescription
typesany[]the types of the values
valuesany[]the values to encode

Returns

string

the hash

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:432


makeRandomWallet

makeRandomWallet(): HDAccount

It generates a random account.

Returns

HDAccount

a new account

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:400


makeRandomWallets

makeRandomWallets(numAccounts?): any[]

It generates a list of random accounts

Parameters

NameTypeDefault valueDescription
numAccountsnumber10the number of accounts to create

Returns

any[]

the array of accounts

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:410


makeWallet

makeWallet(seedphrase, addressIndex?): HDAccount

Given a seedphrase, it returns an account.

Parameters

NameTypeDefault valueDescription
seedphrasestringundefinedthe seedphrase to be used to generate the account
addressIndexnumber0the address index

Returns

HDAccount

an account

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:378


makeWallets

makeWallets(seedphrase, numAccounts?): any[]

Given a seedphrase generates multiple accounts

Parameters

NameTypeDefault valueDescription
seedphrasestringundefinedthe seedphrase to be used to generate the account
numAccountsnumber10the number of accounts to create

Returns

any[]

the array of accounts

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:388


noDidPrefixed

noDidPrefixed(input): string

Parameters

NameType
inputstring

Returns

string

Defined in

src/utils/ConversionTypeHelpers.ts:14


noZeroX

noZeroX(input): string

Parameters

NameType
inputstring

Returns

string

Defined in

src/utils/ConversionTypeHelpers.ts:5


objectPromiseAll

objectPromiseAll(obj): Promise\<{}>

Parameters

NameType
objObject

Returns

Promise\<{}>

Defined in

src/utils/PromiseResolver.ts:11


parseEther

parseEther(value): bigint

Converts a ether value into wei.

Parameters

NameTypeDescription
valuestringThe string value to convert

Returns

bigint

The BigInt representation of value in wei

Example

parseEther('1.0')
// 1000000000000000000n

parseEther('-0.5')
// -500000000000000000n

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:502


parseUnits

parseUnits(value, decimals?): bigint

Returns a BigInt representation of value, parsed with decimal digits.

Parameters

NameTypeDefault valueDescription
valuestringundefinedThe string value to convert
decimalsnumber18The number of decimals

Returns

bigint

The BigInt representation of value parsed with decimals

Example

parseUnits('1.0', 18)
// 1000000000000000000n

parseUnits('121.0', 9)
// 121000000000n

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:465


searchAbiEvent

searchAbiEvent(abi, eventName): AbiEvent

It searchs an ABI event in the ABI.

Parameters

NameTypeDescription
abiAbithe ABI of the contract
eventNamestring-

Returns

AbiEvent

the event found

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:263


searchAbiFunction

searchAbiFunction(abi, funcName, args?): AbiFunction

It searchs an ABI function in the ABI.

Parameters

NameTypeDefault valueDescription
abiAbiundefinedthe ABI of the contract
funcNamestringundefinedthe function name
argsany[][]the args of the function

Returns

AbiFunction

the function found

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:245


serializeECIES

serializeECIES(ecies): string

Parameters

NameType
eciesany

Returns

string

Defined in

src/common/helpers.ts:88


urlSafeBase64Decode

urlSafeBase64Decode(input): Uint8Array

Parameters

NameType
inputstring

Returns

Uint8Array

Defined in

src/common/helpers.ts:60


urlSafeBase64Encode

urlSafeBase64Encode(input): string

Parameters

NameType
inputUint8Array

Returns

string

Defined in

src/common/helpers.ts:51


zeroPadValue

zeroPadValue(value, length): string

It pads a value with zeros.

Parameters

NameTypeDescription
value`0x${string}` | Uint8Arraythe value to pad
lengthnumberthe expected longitutde of the value

Returns

string

the padded value

Defined in

src/nevermined/utils/BlockchainViemUtils.ts:358


zeroX

zeroX(input): `0x${string}`

Parameters

NameType
inputstring

Returns

`0x${string}`

Defined in

src/utils/ConversionTypeHelpers.ts:4


zeroXTransformer

zeroXTransformer(input?, zeroOutput): string

Parameters

NameTypeDefault value
inputstring''
zeroOutputbooleanundefined

Returns

string

Defined in

src/utils/ConversionTypeHelpers.ts:7