> ## Documentation Index
> Fetch the complete documentation index at: https://docs.restaking.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# 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

```javascript theme={null}
yarn add @blockswaplab/k2-sdk ethers@6.9.0
```

## Importing the libraries

```javascript theme={null}
const { ethers } = require('ethers');
const { K2 } = require("@blockswaplab/k2-sdk");
```

## 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](https://docs.ethers.org/v6/api/providers/thirdparty/) list. For this tutorial, Infura is used.

```javascript theme={null}
const provider = new ethers.InfuraProvider(
    "goerli",
    INFURA_PROJECT_ID,
    INFURA_PROJECT_SECRET
);

const signer = new ethers.Wallet(PRIV_KEY, provider);
```

Once the `provider` and `signer` instances are created, next initialize the K2 SDK.

```javascript theme={null}
const sdk = new K2(signer);
```

> 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:

```javascript theme={null}
const tx = await sdk.k2Lending.setDelegatedRecipient(lienContractAddress);
```

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:

```javascript theme={null}
const tx = await sdk.pno.reDelegateToPreferredNodeOperator(pnoAddress, amount);
```

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:

```javascript theme={null}
const tx = await sdk.pno.reDelegateToPreferredNodeOperator(signer.address, amount);
```

> 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:

```javascript theme={null}
const tx = await sdk.pno.reDelegateToPreferredNodeOperatorFromNativeDelegation(
    pnoAddress,
    amountToRedelegateInETH
)
```

### 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:

```javascript theme={null}
const tx = await sdk.pno.reDelegateToPreferredNodeOperatorFromNativeDelegation(
    signer.address,
    amountToRedelegateInETH
)
```

> If the validator was registered using a different address, please use that address in place of `signer.address`
