9

How to link library in browser-solidity? While creating a contract using library, solidity compiler requires to link the contract with the library. But there is no options in the browser to provide it. Contract is not created as it has lib's placeholders in bytecode similar to _______LibName_________

enter image description here

marked as duplicate by niksmac, Badr Bellaj, Nicolas Massart, Matthew Schmidt, Tjaden Hess Jan 23 '17 at 2:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

10

Browser-solidity is able to import library code from GitHub (importing from Swarm is on the way). E.g. you can write:

pragma solidity ^0.4.0;

import "github.com/ethereum/dapp-bin/library/stringUtils.sol";

contract test {
    function foo() returns (bool){
        string memory a = "hello";
        string memory b = "world";
        return StringUtils.equal(a, b);
    }
}

When you press Create button, two contracts will be created on the blockchain: one for the library code and another one for the contract. Library address will be linked into the test contract automatically.


Please note, that you need to drop blob/<branch name> from URL.

Original URL:
https://github.com/ethereum/dapp-bin/blob/master/library/stringUtils.sol

URL to import (without https:// and blob/master/):
github.com/ethereum/dapp-bin/library/stringUtils.sol

Not the answer you're looking for? Browse other questions tagged or ask your own question.