bn.getMpcProvider
▸ getMpcProvider(): Web3Provider
description
The api to get web3 provider
remark
supported jssdk >= 4.0.0
example
//eg1: get web3 provider and then request with method
bn.getMpcProvider()
.request({
method: 'eth_requestAccounts'
})
.then(accounts => {
console.log('accounts', accounts)
})
Returns
Web3Provider
Class: Web3Provider
Name | Type | Description |
---|---|---|
idMapping | default | |
rpc | default | |
callbacks | Map <number , JsonRpcCallback <JsonRpcCallbackResponse >> | |
wrapResults | Map <number , boolean > | |
isDebug | undefined | boolean | |
address | string [] = [] | |
ready | boolean = false | |
chainId? | string | The chain ID of the currently connected Ethereum chain.; See chainId.network for more information. |
_rpcHooks | RPCHooks | |
isProcessingRequestAccounts | boolean = false | |
ProviderRpcError | typeof ProviderRpcError | |
setChainId | (value? ): void | |
setAddress | (value? ): void | |
setRpc | (rpcUrl , rpcHooks? ): void | |
request | (payload ): Promise <EthJsonRpc [T ]["response" ]["result" ]> | |
isConnected | (): boolean | deprecated Listen to "connect" event instead. |
enable | (): Promise <Maybe <string []>> | deprecated Use request({ method: "eth_requestAccounts" }) instead. |
send | (payload ): EthJsonRpc [T ]["response" ] | deprecated Use request() method instead. |
sendAsync | (payload , callback ): void | deprecated Use request() method instead. |
_request | (payload , wrapResult? ): Promise <undefined | null | string | boolean | object | JsonRpcSuccess <UnknownResponse > | JsonRpcSuccess <string []> | JsonRpcSuccess <string > | JsonRpcSuccess <boolean > | JsonRpcSuccess <null > | JsonRpcSuccess <never > | ( (undefined | string | object )[] | ( (undefined | string )[]> | |
eth_accounts | (): string [] | |
eth_coinbase | (): undefined | string | |
net_version | (): null | string | |
eth_chainId | (): null | string | |
eth_sign | (payload ): void | |
personal_sign | (payload ): void | |
eth_signTypedData | (payload , version ): void | |
getAccounts | (): Promise <string []> | |
requestAccounts | (): Promise <string []> | Metamask 行為描述 |
比照流程:https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/controllers/permissions/permissionsMethodMiddleware.js | ||
eth_sendTransaction | (payload ): Promise <Maybe <string >> | |
populateTransaction | (payload ): Promise <EthTransaction > | populate the transaction params |
eth_sendRawTransaction | (payload ): void | |
wallet_watchAsset | (payload ): void | |
wallet_addEthereumChain | (payload ): Promise <Maybe <null >> | |
wallet_switchEthereumChain | (payload ): Promise <Maybe <null >> | |
postMessage | (action , id , object ): void | |
_isJsonRpc | (result ): result is JsonRpcSuccess<UnknownResponse> | |
sendResponse | (id , result ): void | |
sendError | (id , error ): void |
setChainId
▸ setChainId(value?
): void
Parameters
Name | Type |
---|---|
value? | string | number |
Returns
void
setAddress
▸ setAddress(value?
): void
Parameters
Name | Type | Default value |
---|---|---|
value | string [] | [] |
Returns
void
setRpc
▸ Private
setRpc(rpcUrl
, rpcHooks?
): void
Parameters
Name | Type |
---|---|
rpcUrl | undefined | string |
rpcHooks? | RPCHooks |
Returns
void
request
▸ request<T
>(payload
): Promise
<EthJsonRpc
[T
]["response"
]["result"
]>
Type parameters
Name | Type |
---|---|
T | extends keyof EthJsonRpc |
Parameters
Name | Type |
---|---|
payload | EthJsonRpc [T ]["request" ] |
Returns
Promise
<EthJsonRpc
[T
]["response"
]["result"
]>
isConnected
▸ isConnected(): boolean
deprecated
Listen to "connect" event instead.
Returns
boolean
enable
▸ enable(): Promise
<Maybe
<string
[]>>
deprecated
Use request({ method: "eth_requestAccounts" }) instead.
Returns
Promise
<Maybe
<string
[]>>
send
▸ send<T
>(payload
): EthJsonRpc
[T
]["response"
]
deprecated
Use request() method instead.
Type parameters
Name | Type |
---|---|
T | extends keyof EthJsonRpc |
Parameters
Name | Type |
---|---|
payload | EthJsonRpc [T ]["request" ] |
Returns
EthJsonRpc
[T
]["response"
]
sendAsync
▸ sendAsync<T
>(payload
, callback
): void
deprecated
Use request() method instead.
Type parameters
Name | Type |
---|---|
T | extends keyof EthJsonRpc |
Parameters
Name | Type |
---|---|
payload | EthJsonRpc [T ]["request" ] | EthJsonRpc [T ]["request" ][] |
callback | JsonRpcCallback <EthJsonRpc [T ]["response" ] | EthJsonRpc [T ]["response" ][]> |
Returns
void
_request
▸ Private
_request(payload
, wrapResult?
): Promise
<undefined
| null
| string
| boolean
| object
| JsonRpcSuccess
<UnknownResponse
> | JsonRpcSuccess
<string
[]> | JsonRpcSuccess
<string
> | JsonRpcSuccess
<boolean
> | JsonRpcSuccess
<null
> | JsonRpcSuccess
<never
> | (undefined
| string
| object
)[] | (undefined
| string
)[]>
Parameters
Name | Type | Default value |
---|---|---|
payload | JsonRpcRequest <"unknown" , unknown > | JsonRpcRequest <"eth_accounts" , undefined > | JsonRpcRequest <"eth_coinbase" , undefined > | JsonRpcRequest <"net_version" , undefined > | JsonRpcRequest <"eth_chainId" , undefined > | JsonRpcRequest <"eth_sign" , [string , string ]> | JsonRpcRequest <"personal_sign" , [string ]> | JsonRpcRequest <"personal_ecRecover" , [string , string ]> | JsonRpcRequest <"eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4" , [string , string ]> | JsonRpcRequest <"eth_sendTransaction" , [EthTransaction ]> | JsonRpcRequest <"eth_sendRawTransaction" , [string ]> | JsonRpcRequest <"eth_signTransaction" , [EthTransaction ]> | JsonRpcRequest <"eth_requestAccounts" , undefined > | JsonRpcRequest <"eth_privateRequestAccounts" , undefined > | JsonRpcRequest <"eth_getTransactionCount" , [string , BlockTag ]> | JsonRpcRequest <"eth_gasPrice" , undefined > | JsonRpcRequest <"eth_estimateGas" , [EthTransaction ]> | JsonRpcRequest <"wallet_watchAsset" , WatchAssetParameter > | JsonRpcRequest <"wallet_addEthereumChain" , [Pick <AddEthereumChainParameter , "chainName" | "nativeCurrency" | "rpcUrls" | "blockExplorerUrls" | "iconUrls" > & { chainId : string }]> | JsonRpcRequest <"wallet_switchEthereumChain" , [Omit <SwitchEthereumChainParameter , "chainId" > & { chainId : string }]> | JsonRpcRequest <"eth_newFilter" , never > | JsonRpcRequest <"eth_newBlockFilter" , never > | JsonRpcRequest <"eth_newPendingTransactionFilter" , never > | JsonRpcRequest <"eth_uninstallFilter" , never > | JsonRpcRequest <"eth_subscribe" , never > | undefined |
wrapResult | boolean | true |
Returns
Promise
<undefined
| null
| string
| boolean
| object
| JsonRpcSuccess
<UnknownResponse
> | JsonRpcSuccess
<string
[]> | JsonRpcSuccess
<string
> | JsonRpcSuccess
<boolean
> | JsonRpcSuccess
<null
> | JsonRpcSuccess
<never
> | (undefined
| string
| object
)[] | (undefined
| string
)[]>
eth_accounts
▸ Private
eth_accounts(): string
[]
Returns
string
[]
eth_coinbase
▸ Private
eth_coinbase(): undefined
| string
Returns
undefined
| string
net_version
▸ Private
net_version(): null
| string
Returns
null
| string
eth_chainId
▸ Private
eth_chainId(): null
| string
Returns
null
| string
eth_sign
▸ Private
eth_sign(payload
): void
Parameters
Name | Type |
---|---|
payload | JsonRpcRequest <"eth_sign" , [string , string ]> |
Returns
void
personal_sign
▸ Private
personal_sign(payload
): void
Parameters
Name | Type |
---|---|
payload | JsonRpcRequest <"personal_sign" , [string ]> |
Returns
void
eth_signTypedData
▸ Private
eth_signTypedData(payload
, version
): void
Parameters
Name | Type |
---|---|
payload | JsonRpcRequest <"eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4" , [string , string ]> |
version | V3 | V4 |
Returns
void
getAccounts
▸ Private
getAccounts(): Promise
<string
[]>
Returns
Promise
<string
[]>
requestAccounts
▸ Private
requestAccounts(): Promise
<string
[]>
Metamask 行為描述 比照流程:https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/controllers/permissions/permissionsMethodMiddleware.js
Returns
Promise
<string
[]>
eth_sendTransaction
▸ Private
eth_sendTransaction(payload
): Promise
<Maybe
<string
>>
Parameters
Name | Type |
---|---|
payload | JsonRpcRequest <"eth_sendTransaction" , [EthTransaction ]> |
Returns
Promise
<Maybe
<string
>>
populateTransaction
▸ Private
populateTransaction(payload
): Promise
<EthTransaction
>
populate the transaction params
Parameters
Name | Type |
---|---|
payload | JsonRpcRequest <"eth_sendTransaction" , [EthTransaction ]> |
Returns
Promise
<EthTransaction
>
eth_sendRawTransaction
▸ Private
eth_sendRawTransaction(payload
): void
Parameters
Name | Type |
---|---|
payload | JsonRpcRequest <"eth_sendRawTransaction" , [string ]> |
Returns
void