[solidity] contract, library import하기

HyeongA·2023년 5월 24일
0

Blockchain_dev

목록 보기
9/20
post-thumbnail

import

1) local내 타 컨트랙트 받아오기

: import './위치/파일명';

//B_smartContract 받아오기
import './b.sol'; 
contract A {
    B_SmartContract b = new B_SmartContract();
    function add(uint _a, uint _b) public view returns(uint) {
        return b.add(_a, _b);
    }
contract B_SmartContract {
    function add(uint _a, uint _b) public pure returns(uint) {
        return (_a+_a+_b);
    }
}

2) 외부 라이브러리 받아오기

//외부 라이브러리 사용하는 법(git)
import "@openzeppelin/contracts/utils/Strings.sol";
contract C{
    function UtoS(uint _n) public pure returns(string memory){
        return  Strings.toString(_n);
    } 
}
profile
Solidity | React | Python

0개의 댓글