Ethereum Asked by kantus jee on November 12, 2021
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;
}
}
THE STEPS I AM FOLLOWING ARE:-
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)
})
ANY HELP WOULD BE APPRECIATED THANK YOU.
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?
Answered by Majd TL on November 12, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP