StakingClient
@human-protocol/sdk
@human-protocol/sdk / staking / StakingClient
Class: StakingClient
Defined in: staking.ts:104
Introduction
This client enables performing actions on staking contracts and obtaining staking information from both the contracts and subgraph.
Internally, the SDK will use one network or another according to the network ID of the runner. To use this client, it is recommended to initialize it using the static build method.
static async build(runner: ContractRunner): Promise<StakingClient>;A Signer or a Provider should be passed depending on the use case of this module:
Signer: when the user wants to use this model to send transactions calling the contract functions.
Provider: when the user wants to use this model to get information from the contracts or subgraph.
Installation
npm
npm install @human-protocol/sdkyarn
Code example
Signer
Using private key (backend)
Using Wagmi (frontend)
Provider
Extends
BaseEthersClient
Constructors
Constructor
new StakingClient(
runner,networkData):StakingClient
Defined in: staking.ts:115
StakingClient constructor
Parameters
runner
ContractRunner
The Runner object to interact with the Ethereum network
networkData
NetworkData
The network information required to connect to the Staking contract
Returns
StakingClient
Overrides
BaseEthersClient.constructor
Properties
escrowFactoryContract
escrowFactoryContract:
EscrowFactory
Defined in: staking.ts:107
networkData
networkData:
NetworkData
Defined in: base.ts:14
Inherited from
BaseEthersClient.networkData
runner
protectedrunner:ContractRunner
Defined in: base.ts:13
Inherited from
BaseEthersClient.runner
stakingContract
stakingContract:
Staking
Defined in: staking.ts:106
tokenContract
tokenContract:
HMToken
Defined in: staking.ts:105
Methods
applyTxDefaults()
protectedapplyTxDefaults(txOptions):Overrides
Defined in: base.ts:35
Internal helper to enrich transaction overrides with network specific defaults.
Aurora networks use a fixed gas price. We always override any user provided gasPrice with the canonical DEFAULT_AURORA_GAS_PRICE to avoid mismatches or tx failures due to an unexpected value. For other networks the user supplied fee parameters are left untouched.
Parameters
txOptions
Overrides = {}
Returns
Overrides
Inherited from
BaseEthersClient.applyTxDefaults
approveStake()
approveStake(
amount,txOptions?):Promise<void>
Defined in: staking.ts:200
This function approves the staking contract to transfer a specified amount of tokens when the user stakes. It increases the allowance for the staking contract.
Parameters
amount
bigint
Amount in WEI of tokens to approve for stake.
txOptions?
Overrides = {}
Additional transaction parameters (optional, defaults to an empty object).
Returns
Promise<void>
Returns void if successful. Throws error if any.
Code example
getStakerInfo()
getStakerInfo(
stakerAddress):Promise<StakerInfo>
Defined in: staking.ts:454
Retrieves comprehensive staking information for a staker.
Parameters
stakerAddress
string
The address of the staker.
Returns
Promise<StakerInfo>
Code example
slash()
slash(
slasher,staker,escrowAddress,amount,txOptions?):Promise<void>
Defined in: staking.ts:392
This function reduces the allocated amount by a staker in an escrow and transfers those tokens to the reward pool. This allows the slasher to claim them later.
Parameters
slasher
string
Wallet address from who requested the slash
staker
string
Wallet address from who is going to be slashed
escrowAddress
string
Address of the escrow that the slash is made
amount
bigint
Amount in WEI of tokens to slash.
txOptions?
Overrides = {}
Additional transaction parameters (optional, defaults to an empty object).
Returns
Promise<void>
Returns void if successful. Throws error if any.
Code example
stake()
stake(
amount,txOptions?):Promise<void>
Defined in: staking.ts:254
This function stakes a specified amount of tokens on a specific network.
approveStakemust be called before
Parameters
amount
bigint
Amount in WEI of tokens to stake.
txOptions?
Overrides = {}
Additional transaction parameters (optional, defaults to an empty object).
Returns
Promise<void>
Returns void if successful. Throws error if any.
Code example
unstake()
unstake(
amount,txOptions?):Promise<void>
Defined in: staking.ts:303
This function unstakes tokens from staking contract. The unstaked tokens stay locked for a period of time.
Must have tokens available to unstake
Parameters
amount
bigint
Amount in WEI of tokens to unstake.
txOptions?
Overrides = {}
Additional transaction parameters (optional, defaults to an empty object).
Returns
Promise<void>
Returns void if successful. Throws error if any.
Code example
withdraw()
withdraw(
txOptions?):Promise<void>
Defined in: staking.ts:353
This function withdraws unstaked and non-locked tokens from staking contract to the user wallet.
Must have tokens available to withdraw
Parameters
txOptions?
Overrides = {}
Additional transaction parameters (optional, defaults to an empty object).
Returns
Promise<void>
Returns void if successful. Throws error if any.
Code example
build()
staticbuild(runner):Promise<StakingClient>
Defined in: staking.ts:143
Creates an instance of StakingClient from a Runner.
Parameters
runner
ContractRunner
The Runner object to interact with the Ethereum network
Returns
Promise<StakingClient>
An instance of StakingClient
Throws
Thrown if the provider does not exist for the provided Signer
Throws
Thrown if the network's chainId is not supported
Last updated