# 2. Deploying Smart Contract

You can use Remix Online IDE or use truffle to deploy above `MyERC721Card` smart contract.

## 2.1 Deploying smart contract using Remix Online IDE <a href="#id-2-1-deploying-smart-contract-using-klaytn-ide" id="id-2-1-deploying-smart-contract-using-klaytn-ide"></a>

* Please visit [Klaytn Plugin for Remix](https://ide.klaytn.foundation) and create a `MyERC721Card` contract. The complete source code is given at [Writing ERC-721 Smart Contract](/content/smart-contract/sample-contracts/erc-721/1-erc721.md).
* Create an account to deploy the contract with.
  * If you do not have an account yet, create one at <https://baobab.wallet.klaytn.foundation/create> or <https://toolkit.klaytn.foundation/account/accountKeyLegacy>.
  * Get some test KLAY from the faucet - <https://baobab.wallet.klaytn.foundation/faucet>
* Let's deploy `MyERC721Card.sol` as below.

![ERC721-1-deploy](/files/dk4uzH85uSP9rwGu0Geh)

Now `MyERC721Card` is live! You can mint and transfer cards which are ERC-721 compatible non-fungible tokens.

Let's mint two cards, i.e. `King` and `Queen` cards, for account `0x2645BA5Be42FfEe907ca8e9d88f6Ee6dAd8c1410` as below.

![ERC721-2-mint-king](/files/psDXKLj0YjpDvx3dW3uE) ![ERC721-3-mint-queen](/files/C76AcqbKdqVjZILV3ed9)

Now we have minted two cards and let's check the status of these `MyERC721Card` non-fungible token.

![ERC721-4-cards-status](/files/MRIFlNK8T0ESOfJiCEMd)

* `balanceOf` shows that account `0x2645BA5Be42FfEe907ca8e9d88f6Ee6dAd8c1410` has two cards.
* `cards` with parameter `1` shows that `MyERC721Card` with token ID `1` is a `Queen` of level 1.
* `ownerOf` with parameter `0` shows that owner of `MyERC721Card` with token ID `0` is `0x2645BA5Be42FfEe907ca8e9d88f6Ee6dAd8c1410`.

## 2.2 Deploying smart contract using truffle <a href="#id-2-2-deploying-smart-contract-using-truffle" id="id-2-2-deploying-smart-contract-using-truffle"></a>

You should have installed [node.js](https://nodejs.org/) in your environment. Please take a look at [Installing Node.js via package manager](https://nodejs.org/en/download/package-manager/) to install node.js using package manager in various environment.

```
$ mkdir klaytn
$ cd klaytn
$ npm init # initialize npm at the erc20token directory
$ npm install truffle@4.1.15
$ npm install caver-js@latest # installing caver-js
$ ln -s node_modules/truffle/build/cli.bundled.js truffle
$ export PATH=`pwd`:$PATH
```

Now you have installed truffle and caver-js which are required to deploy smart contracts.

Let's prepare `truffle` and a smart contract `MyERC721Card.sol`.

```
$ mkdir myerc721
$ cd myerc721
$ truffle init
```

Now you will have following directory structures.

```
.
├── contracts
│   ├── Migrations.sol
├── migrations
│   └── 1_initial_migration.js
└── truffle-config.js
```

After write `MyERC721Card.sol` and locate it to `contracts` directory, directory structure will be as follows.

Now you will have following directory structures.

```
.
├── contracts
│   ├── Migrations.sol
│   └── MyERC721Card.sol
├── migrations
│   └── 1_initial_migration.js
└── truffle-config.js
```

Also, edit `1_initial_migration.js` as shown below to deploy the `MyERC721Card` contract.

```javascript
const Migrations = artifacts.require("./Migrations.sol");
const MyERC721Card = artifacts.require("./MyERC721Card.sol");
module.exports = function(deployer) {
  deployer.deploy(Migrations);
  deployer.deploy(MyERC721Card)
};
```

You also have to configure `truffle-config.js` to deploy the smart contract to Klaytn network. This is the same step described at [Deploying a Smart Contract using Truffle](/content/getting-started/quick-start/deploy-a-smart-contract.md#deploying-a-smart-contract-using-truffle)

```
// truffle-config.js
module.exports = {
    networks: {
        baobab: {
            host: '127.0.0.1',
            port: 8551,
            from: '0xabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd', // enter your account address
            network_id: '1001', // Baobab network id
            gas: 20000000, // transaction gas limit
            gasPrice: 250000000000, // gasPrice of Baobab is 250 ston
        },
    },
    compilers: {
      solc: {
        version: "0.5.12"    // Specify compiler's version to 0.5.12
      }
  }
};
```

Now you are all ready, let's deploy `MyERC721Card.sol` using the following command.

```
$ truffle deploy --network baobab --reset
Compiling ./contracts/MyERC721Card.sol...
Writing artifacts to ./build/contracts

Using network 'baobab'.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0x5a947f076f4570dff8ff18b1ae3557e27dd69c92ce38a3c97fad8f5355914066
  Migrations: 0x0d737e9865e5fc4c1ff53744fd2c13c52a44b9bc
  Deploying MyERC721Card...
  ... 0x1571e80552dab1d67260e8914e06d9b16ccae16fb698c750f6a09aab12517bc1
  MyERC721Card: 0xc3d282926871c505f334d0f2c85ad52758347831
Saving successful migration to network...
  ... 0x5b984b3f79c425d80470a96d5badb857fc05e7f31d94423044ae3119c639aa77
Saving artifacts...
```

The console output shows that the transaction hash for deploying `MyERC721Card` is `0x1571e80552dab1d67260e8914e06d9b16ccae16fb698c750f6a09aab12517bc1` and the address of `MyERC721Card` is `0xc3d282926871c505f334d0f2c85ad52758347831`.


---

# 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://archive-docs.klaytn.foundation/content/smart-contract/sample-contracts/erc-721/2-erc721.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.
