# Test bridge

**Initialize token contracts**

* Create NFTs on Kylin

For Kylin we'll setup the collection and schema then mint an asset to the test contract.  If you have a pre existing NFT, you can send it to the Kylin test account.

{% tabs %}
{% tab title="Kylin" %}

```bash
export AUTHOR=$KYLIN_TEST_ACCOUNT
export COLLECTION_NAME=nftauthcoll2 # create a different one because this one's taken
export ALLOW_NOTIFY=1
export AUTHORIZED_ACCOUNTS=[$KYLIN_TEST_ACCOUNT] # add additional accounts if necessary
export NOTIFY_ACCOUNTS=[""]
export MARKET_FEE=0.01 # cause we're fair people
export DATA=[]
export SCHEMA_NAME=nftauthschem
export SCHEMA_FORMAT=[ {name: "name", type: "string"}, {name: "series", type: "string"}, {name: "moment", type: "string"}, {name: "description", type: "string"}, {name: "img", type: "image"}, {name: "backimg", type: "string"}, {name: "rarity", type: "string"} ]
# not working, if you know how to make it (passing array as variable) work, please edit!!
# cleos -u $KYLIN_ENDPOINT push action $KYLIN_TOKEN_ACCOUNT createcol "[\"$AUTHOR\",\"$COLLECTION_NAME\",\"$ALLOW_NOTIFY\",\"$AUTHORIZED_ACCOUNTS\",\"$NOTIFY_ACCOUNTS\",\"$MARKET_FEE\",\"$DATA\"]" -p $KYLIN_TEST_ACCOUNT@active

# create collection
cleos -u $KYLIN_ENDPOINT push transaction '{
  "delay_sec": 0,
  "max_cpu_usage_ms": 0,
  "actions": [
    {
      "account": "bridgeassets",
      "name": "createcol",
      "data": {
        "author": "natdeveloper",
        "collection_name": "nftauthcoll2",
        "allow_notify": true,
        "authorized_accounts": [
          "natdeveloper"
        ],
        "notify_accounts": [],
        "market_fee": 0.01,
        "data": []
      },
      "authorization": [
        {
          "actor": "natdeveloper",
          "permission": "active"
        }
      ]
    }
  ]
}'

# create schema
cleos -u $KYLIN_ENDPOINT push transaction '{
  "delay_sec": 0,
  "max_cpu_usage_ms": 0,
  "actions": [
    {
      "account": "bridgeassets",
      "name": "createschema",
      "data": {
        "authorized_creator": "natdeveloper",
        "collection_name": "nftauthcoll2",
        "schema_name": "nftauthschem",
        "schema_format": [
          {
            "name": "name",
            "type": "string"
          },
          {
            "name": "series",
            "type": "string"
          },
          {
            "name": "moment",
            "type": "string"
          },
          {
            "name": "description",
            "type": "string"
          },
          {
            "name": "img",
            "type": "image"
          },
          {
            "name": "backimg",
            "type": "string"
          },
          {
            "name": "rarity",
            "type": "string"
          }
        ]
      },
      "authorization": [
        {
          "actor": "natdeveloper",
          "permission": "active"
        }
      ]
    }
  ]
}'
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
If you get errors such as **Transaction exceeded the current network usage limit imposed on the transaction**, see the [Kylin](https://docs.liquidapps.io/liquidapps-documentation/eosio-guides/testnet-creation-guides/creating-cryptokylin-account) account setup guides to get more tokens and to stake for more resources.
{% endhint %}

* Mint test tokens

We will mint some test NFT tokens to our test account.&#x20;

{% hint style="warning" %}
Be sure to update the **account name,** the **new asset owner,** the **collection name** and the **actor** signing the transaction.
{% endhint %}

```bash
export AUTHORIZED_MINTER=$KYLIN_TEST_ACCOUNT
export COLLECTION_NAME=$COLLECTION_NAME
export SCHEMA_NAME=$SCHEMA_NAME
export TEMPLATE_ID=-1
export NEW_ASSET_OWNER=$KYLIN_TEST_ACCOUNT
export IMMUTABLE_DATA=[ { "key": "name", "value": [ "string", "The New Silk Road" ] }, { "key": "img", "value": [ "string", "QmSXDsFeNaPa3CJKmn8WKBnA421Zv5r3Ra8n71LZhvEi9s/main/genesis/1.png" ] }, { "key": "backimg", "value": [ "string", "QmSXDsFeNaPa3CJKmn8WKBnA421Zv5r3Ra8n71LZhvEi9s/main/genesis/1_back.jpg" ] }, { "key": "series", "value": [ "string", "Through the Looking Glass" ] }, { "key": "moment", "value": [ "string", "6 - The Silk Road" ] }, { "key": "rarity", "value": [ "string", "genesis" ] }, { "key": "description", "value": [ "string", "Named after an ancient Chinese trade route, the digital silk road is a virtual pathway for the delivery of merchandise." ] } ]
export MUTABLE_DATA=[]
export TOKENS_TO_BACK=[]

cleos -u $KYLIN_ENDPOINT push transaction '{
  "delay_sec": 0,
  "max_cpu_usage_ms": 0,
  "actions": [
    {
      "account": "bridgeassets",
      "name": "mintasset",
      "data": {
        "authorized_minter": "natdeveloper",
        "collection_name": "nftauthcoll2",
        "schema_name": "nftauthschem",
        "template_id": -1,
        "new_asset_owner": "natdeveloper",
        "immutable_data": [ { "key": "name", "value": [ "string", "The New Silk Road" ] }, { "key": "img", "value": [ "string", "QmSXDsFeNaPa3CJKmn8WKBnA421Zv5r3Ra8n71LZhvEi9s/main/genesis/1.png" ] }, { "key": "backimg", "value": [ "string", "QmSXDsFeNaPa3CJKmn8WKBnA421Zv5r3Ra8n71LZhvEi9s/main/genesis/1_back.jpg" ] }, { "key": "series", "value": [ "string", "Through the Looking Glass" ] }, { "key": "moment", "value": [ "string", "6 - The Silk Road" ] }, { "key": "rarity", "value": [ "string", "genesis" ] }, { "key": "description", "value": [ "string", "Named after an ancient Chinese trade route, the digital silk road is a virtual pathway for the delivery of merchandise." ] } ],
        "mutable_data": [],
        "tokens_to_back": []
      },
      "authorization": [
        {
          "actor": "natdeveloper",
          "permission": "active"
        }
      ]
    }
  ]
}'
```

* Register mapping

The collection author for an NFT **must register that NFT with the bridge** before users can transfer.&#x20;

{% hint style="warning" %}
Be sure to update the address to the **atomicnft** contract address
{% endhint %}

```bash
cleos -u $KYLIN_ENDPOINT push transaction '{
  "delay_sec": 0,
  "max_cpu_usage_ms": 0,
  "actions": [
    {
      "account": "maticnftbrdg",
      "name": "regmapping",
      "data": {
        "template_id": -1,
        "schema_name": "nftauthschem",
        "collection_name": "nftauthcoll2",
        "address": "0xc68c97B2c24A79F096D4b6503D9a1C6Eef7ce292",
        "immutable_data": [ { "key": "name", "value": [ "string", "The New Silk Road" ] }, { "key": "img", "value": [ "string", "QmSXDsFeNaPa3CJKmn8WKBnA421Zv5r3Ra8n71LZhvEi9s/main/genesis/1.png" ] }, { "key": "backimg", "value": [ "string", "QmSXDsFeNaPa3CJKmn8WKBnA421Zv5r3Ra8n71LZhvEi9s/main/genesis/1_back.jpg" ] }, { "key": "series", "value": [ "string", "Through the Looking Glass" ] }, { "key": "moment", "value": [ "string", "6 - The Silk Road" ] }, { "key": "rarity", "value": [ "string", "genesis" ] }, { "key": "description", "value": [ "string", "Named after an ancient Chinese trade route, the digital silk road is a virtual pathway for the delivery of merchandise." ] } ],
      },
      "authorization": [
        {
          "actor": "natdeveloper",
          "permission": "active"
        }
      ]
    }
  ]
}'
```

Let's test by sending an NFT across.

```bash
export FROM=$KYLIN_TEST_ACCOUNT
export TO=$KYLIN_BRIDGE_ACCOUNT
export ASSET_ID=1099511627781
export MEMO="0x92Fb8d9402Cbd918092CE6D00bE86A8bdD13559c"
cleos -u $KYLIN_ENDPOINT push action $KYLIN_TOKEN_ACCOUNT transfer "[\"$FROM\",\"$TO\",[\"$ASSET_ID\"],\"$MEMO\"]" -p $KYLIN_TEST_ACCOUNT@active
```

Now let's see if the tokens make it! Navigate to your user account's address

<https://mumbai.polygonscan.com/address/0x92fb8d9402cbd918092ce6d00be86a8bdd13559c>

![](https://4003270724-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTfSc9O76OFJpqcb3QC%2F-Mf-ZI4I7ytQbQWd9bKN%2F-Mf-arCIG1ayVztg4rHe%2Fin.png?alt=media\&token=969c3856-c7c0-4293-ac52-9e37d57f8344)

Now let's send it back!

Go to your NFT contract and scroll to #11. Set operator to **atomictokenpeg contract** account, and approved to 1.

Click on the contract tab, go to Write Contract, and connect using your user's account.

![](https://4003270724-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTfSc9O76OFJpqcb3QC%2F-Ma0R8oHar8PsEFW4CCA%2F-Ma0TdbSNev9qQKBocsL%2F29.png?alt=media\&token=7686c07b-2044-4125-a97e-ba1d980ae66d)

![](https://4003270724-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTfSc9O76OFJpqcb3QC%2F-Mf-X3AoxU85b0L4XAiG%2F-Mf-XN4WbXLnoLLNvBLu%2Fhm.png?alt=media\&token=979eee53-f85c-4a68-ab58-bf9f718a55fb)

Then go to the atomictokenpeg contract and scroll to #4.  Type in the tokenId from the transaction that was sent to your user account.

![](https://4003270724-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTfSc9O76OFJpqcb3QC%2F-Mf-X3AoxU85b0L4XAiG%2F-Mf-YAAXiIx2_uiObikK%2Fhm2.png?alt=media\&token=b2aff64a-1974-469f-a2ea-66121ec16245)

To determine the destination address we're going to use a helper function on our bridge contract.

```bash
cleos -u $EOS_ENDPOINT push action $KYLIN_BRIDGE_ACCOUNT getdest '["YOUR EOSIO USER ACCOUNT HERE"]' -p $KYLIN_BRIDGE_ACCOUNT@active
```

The assertion error will relay the `uint64_t` for the account specified, and you said EOSIO assertion messages weren't good for anything, pish posh, we move on!

`Destination EOSIO Account Name Value: 11075078730411234672`

The token contract is the atomicnft token contract.

![](https://4003270724-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MTfSc9O76OFJpqcb3QC%2F-Mf-Z3rJwF7E-PzdPmFR%2F-Mf-Z8u90vvH5SnZsAEj%2Fsend.png?alt=media\&token=e6bf11ba-0042-45fe-b214-b9602e240c40)

Fire. [Example trx](https://mumbai.polygonscan.com/tx/0xf84b859368738787505e7754b422e0c01b4a404844a63da2bbe38aa850af1f54)

And shazam you've got the nft! <https://kylin.eosq.eosnation.io/tx/4a049d9e60bfb21c17475ca1ee512a728b6e6b7061798880cb23f7b6eb4cddbf>
