Node Cloud Liquid Delegation SDK Tutorial
This guide outlines the steps for performing a liquid delegation to a preferred node operator as a user of the Node Cloud.
Install k2-sdk and ethers
Importing the libraries
Initialising the SDK
The SDK uses version 6 of the ethers.js library and it is recommended to use this library to create a provider and a signer instance, required for signing the transaction. You can use any provider API that you want from this list. For this tutorial, Infura is used.
Once the provider
and signer
instances are created, next initialize the K2 SDK.
The K2 SDK also takes other parameters as input but they are optional, only the Signer is required for liquid delegation.
Approve the Lien contract
Before liquid delegation, you must approve the lien contract by passing the lien contract address to the following function:
Once this transaction is successful, we can proceed with the liquid delegation.
Liquid Delegation to a PNO using your K2 LP Balance
For liquid delegation to either a different PNO or yourself, the following functions from the pno
sub-class can be used:
Delegate to another PNO
You can delegate your K2 LP to a PNO by calling the following function:
where amount is the amount of K2 LP to be delegated in string.
Delegate to yourself
Assuming your signer wallet address is the same as the one used for registering your validator, you can delegate to yourself by calling:
If the validator was registered using a different address, please use that address in place of
signer.address
Liquid Delegation to a PNO from Native Delegation balance
The max liquid delegation you can give to any PNO is 24 ETH * number of native delegations.
For liquid delegation to either a different PNO or yourself from Native Delegation balance, the following functions from the pno
sub-class can be used:
Delegate to another PNO
You can delegate to a PNO by calling the following function:
Delegate to yourself
Assuming your signer wallet address is the same as the one used for registering your validator, you can delegate to yourself by calling:
If the validator was registered using a different address, please use that address in place of
signer.address