Class: EthersConnection

EthersConnection(options)

Manage the connection(s) to the blockchain.

This is an internal class and should not be used directly. All service class instances have a property named `ethersConnection` which is an instance of this class. For optimization, generally the same instance of this class is shared across all service class instances.

Constructor

new EthersConnection(options)

Create an instance of the EthersConnection class to manage the blockchain connection(s).
Parameters:
Name Type Description
options See CaskSDK configuration.
See:

Methods

(async) estimateGas(request) → {number}

Estimate gas for a transaction.
Parameters:
Name Type Description
request Object of args passed to sendTransaction
Returns:
Estimated amount of gas needed
Type
number

(async) init(args)

Initialize a blockchain connection.
Parameters:
Name Type Description
args Object Function arguments
Properties
Name Type Attributes Description
chainId Object <optional>
Chain ID to connect to. Defaults to the defaultChain for the environment.
signer Object <optional>
Initial signer to use

onEstimateGas(handler)

Register a handler to receive a callback when the EthersConnection estimates gas.
Parameters:
Name Type Description
handler Callback handler

onSwitchChain(handler)

Register a handler to receive a callback when the EthersConnection switches chains.
Parameters:
Name Type Description
handler Callback handler

onSwitchSigner(handler)

Register a handler to receive a callback when the EthersConnection switches signers.
Parameters:
Name Type Description
handler Callback handler

(async) sendTransaction(transaction) → {string}

Send a transaction with the currently configured signer.
Parameters:
Name Type Description
transaction Transaction to send
Returns:
TransactionResponse
Type
string

(async) signMessage(message) → {string}

Sign a message with the currently configured signer.
Parameters:
Name Type Description
message Message to sign
Returns:
Signed message data
Type
string

(async) switchChain(chainId, signeropt)

Switch connected chain.
Parameters:
Name Type Attributes Description
chainId Chain ID to switch to
signer <optional>
Optional signer to switch to as well

(async) switchSigner(signer)

Switch signer to use for write transactions.
Parameters:
Name Type Description
signer New signer to use