my library

pragma solidity ^0.5.8;

library SafeMath {

    function add(uint256 a,uint256 b) public pure returns (uint256) {
        return a+b;

My contract

pragma solidity ^0.5.8;

import "./SafeMath.sol";

contract Test {

using SafeMath for uint256;

uint256 c = 10;

    function addition() public {
        uint256 a = 10;
        uint256 b = 10;
        c = a.add(b);

    function getValue() view public returns (uint256) {
        return c;



step 1 :- I am compiling SafeMath.sol using commnadline [solc --abi --bin safeMath.sol ]

step 2 :- I am deploying the same with web3 and getting the address as 0x785763........

step3 :- I am linking and compiling the Test.sol contract using the command solc --abi --bin Test.sol --libraries SafeMath:0x785763........ -o bin

step4 :- I am deploying this contract and trying to just get the value of c without performing the addition operation ,i am getting default value 0

also no events gets fired in addition method inside contract(not shown in this code)

//--------------------------------------------------- //MY WEB3 CODE

var UserRepositoryInstance1 = web3.eth.contract(UserRepositoryABI1).at(UserRepositoryAddress1);

app.get('/checkAdd', function (req, res) { web3.eth.defaultAccount = web3.eth.coinbase; var i=UserRepositoryInstance1.getValue(); console.log(i) })


  • how are you calling the value c? with web3js ? remix? web3j? – Majd TL May 31 '19 at 9:19

Try to add this --link before --libraries, and see this answer it could help you

What are the steps to compile and deploy a library in Solidity?

  • yes i tried that got "linking complete" but the problem is the same – kantus jee May 31 '19 at 12:09
  • my contract bytecode has the address of library contained in it ...the deployment of the contract is also done without any error – kantus jee May 31 '19 at 12:12
  • but when i call getValue() from node(web3) i get the default value 0.. – kantus jee May 31 '19 at 12:13
  • if i compile Test.sol first using command solc --optmize --bin Test.sol – kantus jee May 31 '19 at 12:20
  • can you upload your code somewhere? – Majd TL May 31 '19 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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