# Building bridge deposit

To initiate a bridge transaction a user should send a transaction to the [bridge smart contract](/details/contracts.md) on the source chain calling a specific method on the smart contract depending on whether native tokens or ERC20 tokens are being bridged.

### Native token (ETH) interactions

Users should call the `depositNative` method on the source chain [smart contract](/details/contracts.md).

This function takes one parameter:

* `payload`(string): encrypted block with destination data

See **payload encoding** below to understand how to encode payload data.

{% hint style="danger" %}
Transactions with invalid payload data will be rejected and may result in funds locked in bridge contracts. It is extremely important to construct the payload according to instructions found in this documentation.
{% endhint %}

## ERC20 interactions

Users should call the `deposit` method on the source chain [smart contract](/details/contracts.md).

This function takes three parameters:

* `token`(address): the address of the ERC20 being transferred
* `amount`(uint256): amound being transferred
* `payload`(string): encrypted block with destination data

See **payload encoding** below to understand how to encode payload data.&#x20;

{% hint style="danger" %}
Transactions with invalid payload data will be rejected and may result in funds locked in bridge contracts. It is extremely important to construct the payload according to instructions found in this documentation.
{% endhint %}

## Payload encoding

The payload is an encrypted json which is included as part of the contract call making the single blockchain interaction all that's required to trigger a private deposit process.

The expected structure of the payload is shown below.

<pre><code><strong>{
</strong>    "dest_chain": 123456,
    "dest_token": "0x1234567890...",
    "dest_address": "0x1234567890...",
    "dest_amount": 1000000000000
}
</code></pre>

The `dest_amount` param contains the value expected at the destination and is calculated based on the amount of the token that was deposited, minus the operator and broadcast fee that can be determined by calling [`getBridgingQuote`](https://goneuronxyz.gitbook.io/neuron/integrations/api#get-bridging-quote).

This json block should be encrypted using the operator key below.

```
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAstGb5VVGRCuXLNiYy5Lp
d0OydrxwS2A1ZRMTp41Q3NyaQuAVo5KYp5wPcZ2Rp+ExzNxDKMWWJXWXeUNEUMKM
8h5TO6khTShru2ffw2HMvnd6W9/MWiN/lGczsXrp9ITRcCu8F238u0s8vvlmkQnU
gUrU9Xk1TKWV1fno0fzPuFxQTaBuv0QAKIbxjDKgcHnUG1+NPlHfPTUd0SFIPKHq
vaCQhT+4rBztCg0xcd0OvOVRZUq4W11D+enPU9bAWTEMYo5B5YqDbPr7lDW31qNu
yew/0A4jhKS70+HfCr8fxwGJ7n+RhaLk9CtJ0Gz9G9hbAClNYnuhgviHROV7vW6R
QwIDAQAB
-----END PUBLIC KEY-----
```

An example of how this can be done using the `JSEncrypt` library is shown below.

```
function getEncryptedTxParams(destChain, destToken, destAddress, destAmountWei) {
    var crypt = new JSEncrypt();
    var pubkey =`-----BEGIN PUBLIC KEY-----...`;
    crypt.setKey(pubkey);

    var params = `{
        "dest_chain": ${destChain},
        "dest_token": "${destToken}",
        "dest_address": "${destAddress}",
        "dest_amount": ${destAmountWei}
    }`;
    
    var encParams = crypt.encrypt(params);
    return encParams;
}
```

For a detailed example of how to combine APIs with building a bridge deposit, see [examples](/integrations/examples.md).

## Mistakes to avoid

Invalid or unsupported dest\_chain (check API)

Invalid or unsupported dest\_token (check API - only some routes are permitted)

Destination amount too high or too low:

* if the destination amount is greater than the input amount deposited minus fee (check API) the deposit will be rejected and funds locked
* if the destination amount is set too low i.e. much lower than the input amount deposited minus fee it will be considered a fee and kept by the protocol, only the dest\_amount will be credited at the destination

<pre><code><strong>{
</strong><strong>    "dest_chain": 123456,
</strong><strong>    "dest_token": "0x1234567890...",
</strong><strong>    "dest_address": "0x1234567890...",
</strong><strong>    "dest_amount": 1000000000000
</strong><strong>}
</strong></code></pre>

#### Partner integrations for referrals

To be eligible to collect referral rewards as part of the partnership program, an additional parameter is required within the bridging payload.

The ref key should contain the partner Ethereum address where payment will be sent.

<pre><code><strong>{
</strong><strong>    "dest_chain": 123456,
</strong><strong>    "dest_token": "0x1234567890...",
</strong><strong>    "dest_address": "0x1234567890...",
</strong><strong>    "dest_amount": 1000000000000,
</strong><strong>    "ref": "0x1234567890..."
</strong><strong>}
</strong></code></pre>


---

# 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.goneuron.xyz/integrations/building-bridge-deposit.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.
