상세 컨텐츠

본문 제목

로컬 컴퓨터와 Remix 연결하기

Programming Language/Solidity

by Yongari 2023. 2. 16. 13:32

본문

 

 

Remixd란?

 

Remixd는 웹브라우저 IDE인 Remix와 로컬 코드를 동기화하는 패키지로 

솔리디티 프로그래밍을 할 때 많이 사용합니다. 

 

 

Remixd 사용법

 

1. 작업할 폴더를 만들고 이동합니다.

 

mkdir test
cd test

 

 

2. 터미널에서 다음 명령어를 입력하고 package.json을 만듭니다. 전부 엔터를 입력해도 됩니다.

:~/work/solidity$ mkdir test
:~/work/solidity$ cd test/
:~/work/solidity/test$ npm init

 

npm init  커맨드 실행시 사진입니다. 

3. 터미널에 다음 커맨드를입력하고 remixd를 설치합니다.

 

npm install -g @remix-project/remixd

 

4. 이후 솔리디티 파일을 만들고 다음 코드를 넣습니다.

 

다음 커맨드를 참고해서 코딩을 하면 됩니다. 

//터미널에서 파일 만들기 
vi test.sol

//vscode가 있으면 그 경로에서 파일을 만들면 됩니다.
//Contract based on [<https://docs.openzeppelin.com/contracts/3.x/erc721>](<https://docs.openzeppelin.com/contracts/3.x/erc721>)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

contract MyNFTs is ERC721URIStorage, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() public ERC721("MyNFT", "NFT") {}

    function mintNFT(address recipient, string memory tokenURI)
        public onlyOwner
        returns (uint256)
    {
        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();
        _mint(recipient, newItemId);
        _setTokenURI(newItemId, tokenURI);

        return newItemId;
    }
}

 

 

이후 다음과 같은 커맨드로 리믹스와 로컬 코드를 동기화 합니다.

remixd -s <remixd_practice 폴더의 절대경로> --remix-ide https://remix.ethereum.org

 

예시))

remixd -s /home/robertseo/work/solidity --remix-ide https://remix.ethereum.org

 

명령이 정상적으로 수행되면 다음과 같은 로그가 화면에 보입니다.

관련글 더보기