# User Configurations

Several tips for our bridge builders are given here!

## Consumer

### Deployment parameters

```solidity
import "./base/BoolConsumerBase.sol";

contract UserMock is BoolConsumerBase {
    ...
    constructor(address anchor_) BoolConsumerBase(anchor_) {}
    ...
}
```

Remember to **pass `anchor` to your contract constructor** to match the fundamental requirement of implementing `BoolConsumerBase.sol`.&#x20;

In addition, when updating `consumer` in a deployed Anchor, the Anchor contract will validate the consumer's configuration as follows:

```solidity
require(
    IBoolConsumerBase(consumer_).anchor() == address(this),
    "Anchor: ANCHOR_MISMATCH"
);
```

Hence, please **DO NOT misconfigure** your consumer contract!&#x20;

Alternatively, you can design an additional function in your consumer contract to update the address of the anchor. However, we do not recommend implementing this function in your contract since in terms of the users' trust, `anchor` should never be changed after the deployment.

### Send cross-chain messages to Anchor

Each consumer contract implemented `BoolConsumerBase.sol` should have inherited the following internal function `_sendToAnchor`. It is the intermediary to send cross-chain messages to the connected Anchor contract.

```solidity
function _sendToAnchor(
    address payable refundAddress,
    bytes32 crossType,
    bytes memory extraFeed,
    uint32 dstChainId,
    address dstAnchor,
    bytes memory payload
) internal virtual returns (bytes32 txUniqueIdentification)
```

A consumer contract must define an upper-level function to implement this core internal function and several tips are provided to implement `_sendToAnchor`:

* **pack** the data to be executed on the destination chain into `payload`, such as using `abi.encode` to pack the target function's parameters.
* pass the **correct** `dstAnchor` since cross-chain messages can only be transmitted to remote anchors within the same AMT bridge.
* request`extraFeed` from our primary contracts based on the value of`crossType`: either [`PURE_MESSAGE`](https://docs.bool.network/smart-contracts/on-chain-endpoint-anchor/anchor.sol#pure_message) or [`VALUE_MESSAGE`](https://docs.bool.network/smart-contracts/on-chain-endpoint-anchor/anchor.sol#value_message).

{% hint style="warning" %}

* Leave `extraFeed` **blank** if `PURE_MESSAGE` selected.
* `VALUE_MESSAGE` has not been enabled yet.
  {% endhint %}

### Receive a Message from Anchor

```solidity
modifier onlyAnchor() {
    require(msg.sender == anchor, "BoolConsumerBase: NOT_ANCHOR");
    _;
}

function receiveFromAnchor(
    bytes memory payload
) external virtual override {}
```

* A consumer contract **must override** `receiveFromAnchor` and define corresponding logic to parse `payload` sent from its corresponding Anchor.
* Two basic operations should be included in the override function: decode payload and forward decoded data to subsequent functions.
* One can use the provided modifier `onlyAnchor` to restrict the accessibility of `receiveFromAnchor`.

## Anchor

### Transfer the ownership of the `Anchor` contract

* The default owner is the initial deployer of an Anchor. One can use [`owner`](https://docs.bool.network/smart-contracts/on-chain-endpoint-anchor/ianchor.sol#owner) to inquire about the address of the current owner.&#x20;
* The most important role played by the owner is to update the connected `consumer`.
* The interface for transferring the ownership of an anchor can be found at [`transferOwnership`](https://docs.bool.network/smart-contracts/on-chain-endpoint-anchor/ianchor.sol#transferownership).
