Voluntary Exits

Learn how to initiate the validator unstaking process

How voluntary exiting works

To initiate unstaking, validators are required to perform a SignedVoluntaryExit transaction, where the transaction is signed using Luganodes' validator keys.

Exiting validators must submit a signed challenge with relevant validator information. Thereafter, the createAndSignChallenge function generates the necessary signature for the exit API request, relying on validator indexes (found in the Get Delegation object response) and the withdrawal address.

We have created scripts to perform the aforementioned operations with ease.

// Install ethers package using a package manager (eg. NPM, YARN)
import {
  BaseWallet,
  SigningKey,
  hashMessage,
  hexlify,
  toUtf8Bytes,
} from 'ethers';

const createAndSignChallenge = async (
  validatorIndexes,
  privateKeyOfWithdrawalAdd,
  withdrawalAddress,
) => {
  const wallet = new BaseWallet(new SigningKey(privateKeyOfWithdrawalAdd));

  // challenge that needs to be signed
  const challenge = JSON.stringify(
    {
      intentToExit:
        'I am signing this message and requesting that Luganodes exit the following validators from the network',
      validatorIndexes, 
      date: Date.now().toString(), 
      address: withdrawalAddress, 
    },
    null,
    2,
  );
  const sign = wallet.signMessageSync(hashMessage(challenge));

  console.log('signature: ', sign);

  // packedChallenge
  const packedChallenge = hexlify(
    toUtf8Bytes(
      '\u0019Ethereum Signed Message:\n' +
        challenge.length.toString() +
        challenge,
    ),
  );
  console.log('packed_challenge', packedChallenge);
};

  
await createAndSignChallenge(
    validatorIndexes, 
    privateKeyOfWithdrawalAdd, 
    withdrawalAddress, 
  );
};

Request Luganodes to submit exits

POST /exit

Request Luganodes to exit a set of validators for a given withdrawal address. The list of validators comes from a challenge that must be signed with the withdrawal address. See the above code snippet for constructing the body for this method.

The challenge and signature needs to be generated using the Exit Messages code snippet given above.

NOTE: If the challenge and signature check out, this submits the voluntary exits and will initiate the process for exiting validators. This method does not return the voluntary exits.

Query Parameters

Name
Type
Description

api_key*

String

API Key provided by Luganodes

key*

String

The withdrawal address of the validator

Request Body

Name
Type
Description

challenge

String

The packed challenge formed using above snippet

signature

String

The packed signature formed using above snippet

Generate Exit Message

POST /exit/message

Request Luganodes to generate an exit message for a set of validators for a given withdrawal address. This message can be broadcasted over the network through an RPC call. The list of validators comes from a challenge that must be signed with the withdrawal address.

The challenge and signature needs to be generated using the Exit Messages code snippet given above.

To verify and broadcast the exit message, you can find the steps here.

Query Parameters

Name
Type
Description

api_key*

String

API Key provided by Luganodes

key*

String

The withdrawal address of the validator

Request Body

Name
Type
Description

page

Number

This specifies the page number of the results to retrieve. It is used for pagination. By default, it is set to 1 to fetch the first page.

per_page

Number

This specifies how many results to return per page. For example, setting per_page to 10 will fetch 10 results per page

challenge

String

The packed challenge formed using above snippet

signature

String

The packed signature formed using above snippet

Generate All Exit Messages

POST /exit/message/all

Request Luganodes to generate exit messages for all current active validators for a given withdrawal address. These messages can be broadcasted over the network through RPC calls. The challenge and signature needs to be generated using the All Exit Messages code snippet given above.

To verify and broadcast the exit messages, you can find the steps here.

Query Parameters

Name
Type
Description

api_key*

String

API Key provided by Luganodes

key*

String

The withdrawal address of the validator

Request Body

Name
Type
Description

challenge

String

The packed challenge formed using above snippet

signature

String

The packed signature formed using above snippet

Last updated