provider/types/index.d.ts

95 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-11-05 22:10:04 +01:00
import Web3 from 'web3'
type Address = string
type Params = {
to: string
gas: string
from: string
data: string
value: string
gasPrice: string
}
type RequestParams = {
method: string
params?: Params[] | object;
}
type ContractRequestParams = {
to: string
gas: string
from: string
methodName: string
data?: string
value?: number
}
export type TransactionStatus =
| 'success'
| 'fail'
| 'pending'
export interface TransactionReceipt {
transactionResult: unknown
status: TransactionStatus
transactionError?: string
}
type GetBalanceParams = {
address: string
}
type WaitForTxReceiptParams = {
2020-11-06 13:14:07 +01:00
txHash: string
2020-11-05 22:10:04 +01:00
}
type BatchRequestParams = {
txs: Params[]
callback?: (params: Promise<string>[]) => void
}
type OnListenerParams = {
method: string
callback: CallableFunction
}
interface ProviderOptions {
id?: string,
rpcUrl?: string,
rpcCallRetryAttempt?: number,
blockGasLimit?: number,
}
interface ProviderInstance {
readonly web3: typeof Web3
readonly config: ProviderOptions
initProvider(provider: unknown): Promise<Address>
sendRequest(params: RequestParams): Promise<TransactionReceipt>
contractRequest(params: ContractRequestParams): Promise<TransactionReceipt>
getBalance(params: GetBalanceParams): Promise<number>
waitForTxReceipt(params: WaitForTxReceiptParams): Promise<TransactionReceipt>
2020-11-06 13:14:07 +01:00
batchRequest(params: BatchRequestParams): Promise<string[]>
checkNetworkVersion(): Promise<string>
2020-11-12 18:01:07 +01:00
getWeb3(rpcUrl: string): Web3
2020-11-18 09:18:02 +01:00
initWeb3(rpcUrl: string): Web3
2020-11-05 22:10:04 +01:00
on(params: OnListenerParams): void
}
declare module '@nuxt/vue-app' {
interface Context {
$axios: ProviderInstance
}
interface NuxtAppOptions {
$axios: ProviderInstance
}
}
declare module 'vue/types/vue' {
interface Vue {
$provider: ProviderInstance
}
2020-11-12 18:01:07 +01:00
}