#StackBounty: #remix #library #compiler How to deploy Library contract separate from the main contract and link it

Bounty: 50

For deployment I am using remix. When I deploy Hello.sol the compiler typically merges SafeMath.sol as a part of the main contract (Hello.sol) and deploys. This adds up library and main contract’s deployment cost as whole. I want to do this operation separately in order to divide deployment cost in to multiple operations.

[Q] Is there any way to first deploy the library contract separately from the main contract and than link it to the main contract on remix? Should I use Truffle or follow different approach for this?

I have following simple contract, remix deploys Hello.sol as as single contract which also includes SafeMath.sol:

SafeMath.sol

pragma solidity ^0.5.0;

library SafeMath {
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "addition overflow");

        return c;
    }
}

Hello.sol

pragma solidity ^0.5.0;

import "./SafeMath.sol";

contract Hello {
    using SafeMath for uint256;
    uint value;

    constructor() public
    {
        value = value.add(100);
    }    
}

enter image description here


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.