# Validator

A **Validator** in the Züs network plays a critical role in ensuring the correctness and integrity of transactions, storage operations, and smart contract executions.&#x20;

Validators verify operations and help maintain consensus within the blockchain ecosystem. They participate in staking mechanisms and earn rewards based on their contributions.

### **Validator Structure**

The **Validator** structure defines key attributes associated with a validator node in the network.

```go
// Validator represents validator information.
type Validator struct {
	ID                       common.Key       `json:"validator_id"`
	BaseURL                  string           `json:"url"`
	PublicKey                string           `json:"-"`
	DelegateWallet           string           `json:"delegate_wallet"`
	MinStake                 common.Balance   `json:"min_stake"`
	MaxStake                 common.Balance   `json:"max_stake"`
	NumDelegates             int              `json:"num_delegates"`
	ServiceCharge            float64          `json:"service_charge"`
	StakeTotal               int64            `json:"stake_total"`
	TotalServiceCharge       int64            `json:"total_service_charge"`
	UncollectedServiceCharge int64            `json:"uncollected_service_charge"`
	LastHealthCheck          common.Timestamp `json:"last_health_check"`
	IsKilled                 bool             `json:"is_killed"`
	IsShutdown               bool             `json:"is_shutdown"`
}
```

#### **Attributes**

* **ID**: Unique identifier for the validator.
* **BaseURL**: The URL through which the validator communicates with the network.
* **PublicKey**: The public key associated with the validator.
* **DelegateWallet**: The wallet address associated with the validator for staking and rewards.
* **MinStake**: Minimum stake required for participation in validation.
* **MaxStake**: Maximum stake allowed for a validator.
* **NumDelegates**: The number of delegates that can stake on this validator.
* **ServiceCharge**: Percentage of rewards charged by the validator as a service fee.
* **StakeTotal**: Total amount staked on the validator.
* **TotalServiceCharge**: Total service charge collected over time.
* **UncollectedServiceCharge**: Pending service charges yet to be collected.
* **LastHealthCheck**: Timestamp of the last health check performed on the validator.
* **IsKilled**: Indicates if the validator is terminated.
* **IsShutdown**: Indicates if the validator is currently shut down.

### **Updating Validator Settings**

Validators can update their settings using the `UpdateValidator` structure:

```go
// UpdateValidator is used during update validator settings calls.
type UpdateValidator struct {
	ID                       common.Key        `json:"validator_id"`
	BaseURL                  *string           `json:"url,omitempty"`
	DelegateWallet           *string           `json:"delegate_wallet,omitempty"`
	MinStake                 *common.Balance   `json:"min_stake,omitempty"`
	MaxStake                 *common.Balance   `json:"max_stake,omitempty"`
	NumDelegates             *int              `json:"num_delegates,omitempty"`
	ServiceCharge            *float64          `json:"service_charge,omitempty"`
	StakeTotal               *int64            `json:"stake_total,omitempty"`
	TotalServiceCharge       *int64            `json:"total_service_charge,omitempty"`
	UncollectedServiceCharge *int64            `json:"uncollected_service_charge,omitempty"`
	LastHealthCheck          *common.Timestamp `json:"last_health_check,omitempty"`
	IsKilled                 *bool             `json:"is_killed,omitempty"`
	IsShutdown               *bool             `json:"is_shutdown,omitempty"`
}
```

#### **Converting UpdateValidator to Blockchain Validation Node**

To apply updates to the blockchain, the `UpdateValidator` struct must be converted to a blockchain-compatible format:

```go
func (v *UpdateValidator) ConvertToValidationNode() *blockchain.UpdateValidationNode {
	blockValidator := &blockchain.UpdateValidationNode{
		ID:      string(v.ID),
		BaseURL: v.BaseURL,
	}

	sp := &blockchain.UpdateStakePoolSettings{
		DelegateWallet: v.DelegateWallet,
		NumDelegates:   v.NumDelegates,
		ServiceCharge:  v.ServiceCharge,
	}

	if v.DelegateWallet != nil ||
		v.MinStake != nil ||
		v.MaxStake != nil ||
		v.NumDelegates != nil ||
		v.ServiceCharge != nil {
		blockValidator.StakePoolSettings = sp
	}

	return blockValidator
}
```

### **Retrieving Validator Information**

#### **Get a Single Validator**

To retrieve information about a specific validator, use the `GetValidator` function:

```go
func GetValidator(validatorID string) (validator *Validator, err error) {
	if !client.IsSDKInitialized() {
		return nil, sdkNotInitialized
	}
	var b []byte
	b, err = screstapi.MakeSCRestAPICall(
		STORAGE_SCADDRESS,
		"/get_validator",
		map[string]string{"validator_id": validatorID},
	)
	if err != nil {
		return nil, errors.Wrap(err, "requesting validator:")
	}
	if len(b) == 0 {
		return nil, errors.New("", "empty response from sharders")
	}
	validator = new(Validator)
	if err = json.Unmarshal(b, validator); err != nil {
		return nil, errors.Wrap(err, "decoding response:")
	}
	return
}
```

#### **Get a List of Validators**

To retrieve a list of validators in the network, use:

```go
func GetValidators(stakable bool) (validators []*Validator, err error) {
	if !client.IsSDKInitialized() {
		return nil, sdkNotInitialized
	}
	var b []byte
	b, err = screstapi.MakeSCRestAPICall(
		STORAGE_SCADDRESS,
		"/validators",
		map[string]string{
			"stakable": strconv.FormatBool(stakable),
		},
	)
	if err != nil {
		return nil, errors.Wrap(err, "requesting validator list")
	}
	if len(b) == 0 {
		return nil, errors.New("", "empty response from sharders")
	}
	if err = json.Unmarshal(b, &validators); err != nil {
		return nil, errors.Wrap(err, "decoding response:")
	}
	return
}
```

### **Managing Validators**

#### **Update Validator Settings**

```go
func UpdateValidatorSettings(v *UpdateValidator) (resp string, nonce int64, err error) {
	if !client.IsSDKInitialized() {
		return "", 0, sdkNotInitialized
	}

	var sn = transaction.SmartContractTxnData{
		Name:      transaction.STORAGESC_UPDATE_VALIDATOR_SETTINGS,
		InputArgs: v.ConvertToValidationNode(),
	}
	resp, _, nonce, _, err = storageSmartContractTxn(sn)
	return
}
```

#### **Shutdown a Validator**

```go
func ShutdownProvider(providerType ProviderType, providerID string) (string, int64, error) {
	if !client.IsSDKInitialized() {
		return "", 0, sdkNotInitialized
	}

	var input = map[string]string{
		"provider_id": providerID,
	}

	var sn = transaction.SmartContractTxnData{
		InputArgs: input,
	}
	switch providerType {
	case ProviderValidator:
		sn.Name = transaction.STORAGESC_SHUTDOWN_VALIDATOR
	default:
		return "", 0, fmt.Errorf("shutdown provider type %v not implemented", providerType)
	}
	hash, _, n, _, err := storageSmartContractTxn(sn)
	return hash, n, err
}
```

Validators are integral to the Züs network, ensuring transaction integrity, maintaining consensus, and securing the blockchain. Properly managing validators, staking, and rewards distribution is crucial for a healthy decentralized ecosystem.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zus.network/zus-docs/system-overview/providers-and-services/validator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
