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_________
1 Answer
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