# Ethereum IBC protocol

## Deposit

If you want to send ERC20 token to the Orbit IBC contract, you should check that the token is registered

`decimal(address tokenAddr)`

Send a deposit transaction to the Orbit IBC contract on the Ethereum MAINNET/ROPSTEN&#x20;

```javascript
// deposit ETH
function deposit(address toAddr, address extraToAddr) payable public
// deposit ERC20 TOKEN
function depositToken(address token, address toAddr, uint amount, address extraToAddr) public
```

If your transaction succeed,&#x20;

```javascript
event Deposit(address tokenAddr, address addr, address toAddr, uint amount, uint depositId, address extraToAddr);
```

Deposit event occur in your transaction&#x20;

Then, Ethereum IBC operator and Validator begin to proceed this deposit

When deposit is completed in the Orbit chain, DepositValidated and BalanceChange event occur

```javascript
// EthpeggingContract
event DepositValidated(address mainAddr, address tokenAddr, address addr, address toAddr, uint amount, uint depositId, address extraToAddr)
// BalanceContract
event BalanceChange(address indexed user, bytes32 indexed tokenId, uint balance);
```

## Withdrawal

Send a withdrawal transaction to OrbitChain BalanceContract

```javascript
function withdrawBySignature(bytes32[] memory bytes32s, uint[] memory uints, address fromAddr, bytes memory destination, bytes memory comment, uint8 v) public
function withdraw(bytes32 tokenId, bytes memory destination, uint amount, bytes memory comment) public
```

Then, Ethereum IBC operator and Validator begin to proceed this withdrawal

When withdrawal is completed in Ethereum, Withdrawal event occur

```javascript
event Withdraw(address tokenAddr, address addr, address toAddr, uint amount, bytes32 whash, uint withdrawId, bytes comment);
```

## Contract Methods

### addToken

{% hint style="info" %}
Only owner address can execute this function.
{% endhint %}

{% code title="Smart Contract" %}

```javascript
function addToken(address _tokenAddr) public onlyOwner;
```

{% endcode %}

| Parameter    | Type    |             Description |
| ------------ | ------- | ----------------------: |
| tokenAddress | address | Token address to append |

### removeToken

{% hint style="info" %}
Only owner address can execute this function.
{% endhint %}

{% code title="Smart Contract" %}

```javascript
function removeToken(address _tokenAddr) public onlyOwner;
```

{% endcode %}

| Parameter    | Type    |             Description |
| ------------ | ------- | ----------------------: |
| tokenAddress | address | Token address to remove |

### relayDepositToken

{% code title="Smart Contract" %}

```javascript
function relayDepositToken(address mainAddr, address fromAddr, address toAddr, address token, uint amount, uint depositId, address extraToAddr) public;
```

{% endcode %}

| Parameter   | Type    |                                       Description |
| ----------- | ------- | ------------------------------------------------: |
| mainAddr    | address | Ethereum reserve contract address on main network |
| fromAddr    | address |                                 Address of sender |
| toAddr      | address |                    Receiver address on OrbitChain |
| token       | address |                                  Address of token |
| amount      | uint256 |                                   Amount of token |
| depositId   | uint256 |                             Identifier of deposit |
| extraToAddr | address |              Extra receiver address on OrbitChain |

### validateDepositToken

{% code title="Smart Contract" %}

```javascript
function validateDepositToken(address mainAddr, address fromAddr, address toAddr, address token, uint amount, uint depositId, address extraToAddr, address validator, uint8 v, bytes32 r, bytes32 s) public;
```

{% endcode %}

You should hash following parameters to sign or validate deposit request.

{% code title="" %}

```
sha256(mainAddr, fromAddr, toAddr, token, amount, depositId, extraToAddr);
```

{% endcode %}

| Parameter   | Type    |                                       Description |
| ----------- | ------- | ------------------------------------------------: |
| mainAddr    | address | Ethereum reserve contract address on main network |
| fromAddr    | address |                                 Address of sender |
| toAddr      | address |                    Receiver address on OrbitChain |
| token       | address |                                  Address of token |
| amount      | uint256 |                                   Amount of token |
| depositId   | uint256 |                             Identifier of deposit |
| extraToAddr | address |              Extra receiver address on OrbitChain |
| validator   | address |                       Address of signer/validator |
| v           | uint8   |                                    v of signature |
| r           | bytes32 |                                    r of signature |
| s           | bytes32 |                                    s of signature |

### checkValidateDepositToken

{% code title="Smart Contract" %}

```javascript
function checkValidateDepositToken(address mainAddr, address fromAddr, address toAddr, address token, uint amount, uint depositId, address extraToAddr) public;
```

{% endcode %}

| Parameter   | Type    |                                       Description |
| ----------- | ------- | ------------------------------------------------: |
| mainAddr    | address | Ethereum reserve contract address on main network |
| fromAddr    | address |                                 Address of sender |
| toAddr      | address |                    Receiver address on OrbitChain |
| token       | address |                                  Address of token |
| amount      | uint256 |                                   Amount of token |
| depositId   | uint256 |                             Identifier of deposit |
| extraToAddr | address |              Extra receiver address on OrbitChain |

### withdraw

{% hint style="info" %}
Only BalanceContract can execute this function.
{% endhint %}

{% code title="Smart Contract" %}

```javascript
function withdraw(uint withdrawId, address user, bytes32 tokenSummary, bytes memory destination, uint amount, bytes memory comment) public;
```

{% endcode %}

| Parameter    | Type    |                              Description |
| ------------ | ------- | ---------------------------------------: |
| withdrawId   | uint256 | Identifier of BalanceContract withdrawal |
| user         | address |             Sender address on OrbitChain |
| tokenSummary | bytes32 |                            Token summary |
| destination  | bytes   |        Address of withdrawal destination |
| uint256      | amount  |                     Amount of withdrawal |
| bytes        | comment |                               Extra data |

### withdraw

{% hint style="info" %}
Only BalanceContract can execute this function.
{% endhint %}

{% code title="Smart Contract" %}

```javascript
function withdraw(uint withdrawId, address user, address extraUser, bytes32 tokenSummary, bytes memory destination, uint amount, bytes memory comment) public;
```

{% endcode %}

| Parameter    | Type    |                                       Description |
| ------------ | ------- | ------------------------------------------------: |
| withdrawId   | uint256 |          Identifier of BalanceContract withdrawal |
| user         | address |                      Sender address on OrbitChain |
| extraUser    | address | Extra sender address on OrbitChain (for Giveback) |
| tokenSummary | bytes32 |                                     Token summary |
| destination  | bytes   |                 Address of withdrawal destination |
| uint256      | amount  |                              Amount of withdrawal |
| bytes        | comment |                                        Extra data |

### relayWithdraw

{% code title="Smart Contract" %}

```javascript
function relayWithdraw(uint withdrawId) public;
```

{% endcode %}

| Parameter  | Type    | Description |
| ---------- | ------- | ----------: |
| withdrawId | uint256 | Withdraw ID |

### validateWithdraw

{% code title="Smart Contract" %}

```javascript
function validateWithdraw(uint withdrawId, address validator, uint8 v, bytes32 r, bytes32 s) public;
```

{% endcode %}

| Parameter  | Type    |                 Description |
| ---------- | ------- | --------------------------: |
| withdrawId | uint256 |                 Withdraw ID |
| validator  | address | Address of signer/validator |

### checkValidateWithdraw

{% code title="Smart Contract" %}

```javascript
function validateWithdraw(uint withdrawId) public;
```

{% endcode %}

| Parameter  | Type    | Description |
| ---------- | ------- | ----------: |
| withdrawId | uint256 | Withdraw ID |

### \_

{% code title="Smart Contract" %}

```javascript
```

{% endcode %}

| Parameter | Type | Description |
| --------- | ---- | ----------: |
|           |      |             |


---

# 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.orbitchain.io/smart-contract-api/ethereum-ibc-contract-api.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.
