# Operator
Source: https://docs.chain.link/chainlink-nodes/contracts/operator

> For the complete documentation index, see [llms.txt](/llms.txt).

Oracles must deploy an onchain contract to handle requests made through the LINK token (Read [Basic Request Model](/architecture-overview/architecture-request-model) to learn more).

When the *Basic Request* model was introduced, node operators had to deploy the legacy [Oracle contract](https://github.com/smartcontractkit/chainlink/blob/contracts-v1.0.0/contracts/src/v0.4/Oracle.sol). However, these come with some limitations, and soon, we introduced [operator contracts](https://github.com/smartcontractkit/chainlink/blob/contracts-v1.3.0/contracts/src/v0.8/operatorforwarder/Operator.sol).

> **NOTE**
>
> <p>Node operators must use *Operator.sol* instead of *Oracle.sol*.</p>

In addition to replacing oracle contracts, operator contracts come with additional features that add more security and flexibility for node operators.

## Features

### Multi-word response

In the EVM architecture, a word is made up of 32 bytes. One limitation of the [Oracle.sol](https://github.com/smartcontractkit/chainlink/blob/contracts-v1.0.0/contracts/src/v0.4/Oracle.sol) contract is that it limits responses to requests to 32 bytes.

[Operator.sol](https://github.com/smartcontractkit/chainlink/blob/contracts-v1.3.0/contracts/src/v0.8/operatorforwarder/Operator.sol) doesn't have the same limitation as it supports a response made of multiple EVM words.

### Factory deployment

To deploy an *Oracle* contract, each node operator has to manually compile and deploy [Oracle.sol](https://github.com/smartcontractkit/chainlink/blob/contracts-v1.0.0/contracts/src/v0.4/Oracle.sol).
The vast number of Solidity versions and steps involved in verifying the contract made it difficult for a client to verify that the deployed contract had not been tampered with.
To fix this, node operators can use a [factory](/chainlink-nodes/contracts/operatorfactory) to deploy an instance of the *operator* contract. Moreover, the factory exposes a getter for clients to check if it deployed a specific *operator* contract address.

### Distributing funds to multiple addresses

A common pain point of node operators is keeping their addresses funded. *Operator*'s `distributeFunds` method allows node operators to fund multiple addresses in a single transaction.

### Flexibility and security

By using multiple externally-owned accounts (EOAs) on Chainlink nodes and [forwarder](/chainlink-nodes/contracts/forwarder) contracts, node operators can set up different transaction-sending strategies.

> **NOTE**
>
> <p>Read more about [forwarders](/chainlink-nodes/contracts/forwarder).</p>

As discussed in the [forwarder](/chainlink-nodes/contracts/forwarder) contracts page:

- Chainlink nodes' EOAs are hot wallets that fulfill requests.
- These EOAs can be associated with one or multiple [forwarder](/chainlink-nodes/contracts/forwarder) contracts. The forwarder's owner must whitelist them to call the [forward](/chainlink-nodes/contracts/forwarder#forward) function. One operator contract owns one or multiple forwarder contracts.
- Node operators manage their forwarder contracts through operator contracts. They use a secure wallet such as hardware or a multisig wallet as the operator's owner account.

## API reference

The operator contract inherits [AuthorizedReceiver](https://github.com/smartcontractkit/chainlink/blob/contracts-v1.3.0/contracts/src/v0.8/operatorforwarder/AuthorizedReceiver.sol) and [ConfirmedOwnerWithProposal](https://github.com/smartcontractkit/chainlink/blob/contracts-v1.3.0/contracts/src/v0.8/shared/access/ConfirmedOwnerWithProposal.sol). Read [AuthorizedReceiver](/chainlink-nodes/contracts/receiver) and [ConfirmedOwnerWithProposal](/chainlink-nodes/contracts/ownership) API references.

### Methods

#### oracleRequest

> **NOTE: Legacy**
>
> Use `operatorRequest` [function](#operatorrequest) instead.

```solidity
function oracleRequest(address sender, uint256 payment, bytes32 specId, address callbackAddress, bytes4 callbackFunctionId, uint256 nonce, uint256 dataVersion, bytes data) external
```

Creates the Chainlink request. This is backwards compatible API with [Oracle.sol contracts](https://github.com/smartcontractkit/chainlink/blob/contracts-v1.0.0/contracts/src/v0.4/Oracle.sol), but the behavior changes because `callbackAddress` is assumed to be the same as the request sender.

##### Parameters

| Name               | Type    | Description                                    |
| ------------------ | ------- | ---------------------------------------------- |
| sender             | address | The sender of the request                      |
| payment            | uint256 | The amount of payment given (specified in wei) |
| specId             | bytes32 | The Job Specification ID                       |
| callbackAddress    | address | The consumer of the request                    |
| callbackFunctionId | bytes4  | The callback function ID for the response      |
| nonce              | uint256 | The nonce sent by the requester                |
| dataVersion        | uint256 | The specified data version                     |
| data               | bytes   | The extra request parameters                   |

#### operatorRequest

```solidity
function operatorRequest(address sender, uint256 payment, bytes32 specId, bytes4 callbackFunctionId, uint256 nonce, uint256 dataVersion, bytes data) external
```

Creates the Chainlink request. Stores the hash of the params as the onchain commitment for the request. Emits [OracleRequest](#oraclerequest-1) event for the Chainlink node to detect.

##### Parameters

| Name               | Type    | Description                                    |
| ------------------ | ------- | ---------------------------------------------- |
| sender             | address | The sender of the request                      |
| payment            | uint256 | The amount of payment given (specified in wei) |
| specId             | bytes32 | The Job Specification ID                       |
| callbackFunctionId | bytes4  | The callback function ID for the response      |
| nonce              | uint256 | The nonce sent by the requester                |
| dataVersion        | uint256 | The specified data version                     |
| data               | bytes   | The extra request parameters                   |

#### fulfillOracleRequest

> **NOTE: Legacy**
>
> Use `fulfillOracleRequest2` [function](#fulfilloraclerequest2) instead.

```solidity
function fulfillOracleRequest(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes32 data) external returns (bool)
```

Called by the Chainlink node to fulfill requests. Given params must hash back to the commitment stored from `oracleRequest`. Will call the callback address' callback function without bubbling up error checking in a `require` so that the node can get paid. Emits [OracleResponse](#oracleresponse) event.

##### Parameters

| Name               | Type    | Description                                                                    |
| ------------------ | ------- | ------------------------------------------------------------------------------ |
| requestId          | bytes32 | The fulfillment request ID that must match the requester's                     |
| payment            | uint256 | The payment amount that will be released for the oracle (specified in wei)     |
| callbackAddress    | address | The callback address to call for fulfillment                                   |
| callbackFunctionId | bytes4  | The callback function ID to use for fulfillment                                |
| expiration         | uint256 | The expiration that the node should respond by before the requester can cancel |
| data               | bytes32 | The data to return to the consuming contract                                   |

##### Return values

| Name | Type | Description                                |
| ---- | ---- | ------------------------------------------ |
|      | bool | Status if the external call was successful |

#### fulfillOracleRequest2

```solidity
function fulfillOracleRequest2(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes data) external returns (bool)
```

Called by the Chainlink node to fulfill requests with multi-word support. Given params must hash back to the commitment stored from `oracleRequest`. Will call the callback address' callback function without bubbling up error checking in a `require` so that the node can get paid. Emits [OracleResponse](#oracleresponse) event.

##### Parameters

| Name               | Type    | Description                                                                    |
| ------------------ | ------- | ------------------------------------------------------------------------------ |
| requestId          | bytes32 | The fulfillment request ID that must match the requester's                     |
| payment            | uint256 | The payment amount that will be released for the oracle (specified in wei)     |
| callbackAddress    | address | The callback address to call for fulfillment                                   |
| callbackFunctionId | bytes4  | The callback function ID to use for fulfillment                                |
| expiration         | uint256 | The expiration that the node should respond by before the requester can cancel |
| data               | bytes   | The data to return to the consuming contract                                   |

##### Return values

| Name | Type | Description                                |
| ---- | ---- | ------------------------------------------ |
|      | bool | Status if the external call was successful |

#### transferOwnableContracts

```solidity
function transferOwnableContracts(address[] ownable, address newOwner) external
```

Transfer the ownership of ownable contracts. This is primarily intended for authorized forwarders but could possibly be extended to work with future contracts.

##### Parameters

| Name     | Type       | Description                      |
| -------- | ---------- | -------------------------------- |
| ownable  | address\[] | list of addresses to transfer    |
| newOwner | address    | address to transfer ownership to |

#### acceptOwnableContracts

```solidity
function acceptOwnableContracts(address[] ownable) public
```

Accept the ownership of an ownable contract. This is primarily intended for authorized forwarders but could possibly be extended to work with future contracts. Emits [OwnableContractAccepted](#ownablecontractaccepted) event.

*Must be the pending owner on the contract*

##### Parameters

| Name    | Type       | Description                                      |
| ------- | ---------- | ------------------------------------------------ |
| ownable | address\[] | list of addresses of Ownable contracts to accept |

#### setAuthorizedSendersOn

```solidity
function setAuthorizedSendersOn(address[] targets, address[] senders) public
```

Sets the fulfillment permission for `senders` on `targets`. Emits [TargetsUpdatedAuthorizedSenders](#targetsupdatedauthorizedsenders) event.

##### Parameters

| Name    | Type       | Description                                    |
| ------- | ---------- | ---------------------------------------------- |
| targets | address\[] | The addresses to set permissions on            |
| senders | address\[] | The addresses that are allowed to send updates |

#### acceptAuthorizedReceivers

```solidity
function acceptAuthorizedReceivers(address[] targets, address[] senders) external
```

Accepts ownership of ownable contracts and then immediately sets the authorized sender list on each of the newly owned contracts. This is primarily intended for authorized forwarders but could possibly be extended to work with future contracts.

##### Parameters

| Name    | Type       | Description                                    |
| ------- | ---------- | ---------------------------------------------- |
| targets | address\[] | The addresses to set permissions on            |
| senders | address\[] | The addresses that are allowed to send updates |

#### withdraw

```solidity
function withdraw(address recipient, uint256 amount) external
```

Allows the node operator to withdraw earned LINK to a given address `recipient`.

*The owner of the contract can be another wallet and does not have to be a Chainlink node*

##### Parameters

| Name      | Type    | Description                           |
| --------- | ------- | ------------------------------------- |
| recipient | address | The address to send the LINK token to |
| amount    | uint256 | The amount to send (specified in wei) |

#### withdrawable

```solidity
function withdrawable() external view returns (uint256)
```

Displays the amount of LINK that is available for the node operator to withdraw.

*We use `1` in place of 0 in storage*

##### Return values

| Name | Type    | Description                                     |
| ---- | ------- | ----------------------------------------------- |
|      | uint256 | The amount of withdrawable LINK on the contract |

#### ownerForward

```solidity
function ownerForward(address to, bytes data) external
```

Forward a call to another contract.

*Only callable by the owner*

##### Parameters

| Name | Type    | Description |
| ---- | ------- | ----------- |
| to   | address | address     |
| data | bytes   | to forward  |

#### ownerTransferAndCall

```solidity
function ownerTransferAndCall(address to, uint256 value, bytes data) external returns (bool success)
```

Interact with other LinkTokenReceiver contracts by calling transferAndCall.

##### Parameters

| Name  | Type    | Description                                            |
| ----- | ------- | ------------------------------------------------------ |
| to    | address | The address to transfer to.                            |
| value | uint256 | The amount to be transferred.                          |
| data  | bytes   | The extra data to be passed to the receiving contract. |

##### Return values

| Name    | Type | Description |
| ------- | ---- | ----------- |
| success | bool | bool        |

#### distributeFunds

```solidity
function distributeFunds(address payable[] receivers, uint256[] amounts) external payable
```

Distribute funds to multiple addresses using ETH sent to this payable function.

Array length must be equal, ETH sent must equal the sum of amounts. A malicious receiver could cause the distribution to revert, in which case it is expected that the address is removed from the list.

##### Parameters

| Name      | Type               | Description       |
| --------- | ------------------ | ----------------- |
| receivers | address payable\[] | list of addresses |
| amounts   | uint256\[]         | list of amounts   |

#### cancelOracleRequest

```solidity
function cancelOracleRequest(bytes32 requestId, uint256 payment, bytes4 callbackFunc, uint256 expiration) external
```

Allows recipient to cancel requests sent to this oracle contract. Will transfer the LINK sent for the request back to the recipient address. Given params must hash to a commitment stored on the contract in order for the request to be valid. Emits [CancelOracleRequest](#canceloraclerequest-1) event.

##### Parameters

| Name         | Type    | Description                                          |
| ------------ | ------- | ---------------------------------------------------- |
| requestId    | bytes32 | The request ID                                       |
| payment      | uint256 | The amount of payment given (specified in wei)       |
| callbackFunc | bytes4  | The requester's specified callback function selector |
| expiration   | uint256 | The time of the expiration for the request           |

#### cancelOracleRequestByRequester

```solidity
function cancelOracleRequestByRequester(uint256 nonce, uint256 payment, bytes4 callbackFunc, uint256 expiration) external
```

Allows requester to cancel requests sent to this oracle contract. Will transfer the LINK sent for the request back to the recipient address. Given params must hash to a commitment stored on the contract in order for the request to be valid. Emits [CancelOracleRequest](#canceloraclerequest-1) event.

##### Parameters

| Name         | Type    | Description                                          |
| ------------ | ------- | ---------------------------------------------------- |
| nonce        | uint256 | The nonce used to generate the request ID            |
| payment      | uint256 | The amount of payment given (specified in wei)       |
| callbackFunc | bytes4  | The requester's specified callback function selector |
| expiration   | uint256 | The time of the expiration for the request           |

#### getChainlinkToken

```solidity
function getChainlinkToken() public view returns (address)
```

Returns the address of the LINK token

This is the public implementation for chainlinkTokenAddress, which is
an internal method of the ChainlinkClient contract.

### Events

#### OracleRequest

```solidity
event OracleRequest(bytes32 specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)
```

#### CancelOracleRequest

```solidity
event CancelOracleRequest(bytes32 requestId)
```

#### OracleResponse

```solidity
event OracleResponse(bytes32 requestId)
```

#### OwnableContractAccepted

```solidity
event OwnableContractAccepted(address acceptedContract)
```

#### TargetsUpdatedAuthorizedSenders

```solidity
event TargetsUpdatedAuthorizedSenders(address[] targets, address[] senders, address changedBy)
```