Questions tagged [library]

Libraries are reusable code. In the context of smart contracts, they are deployed only once at a specific address and their code is reused using DELEGATECALL.

32
votes
2answers
5k views

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

I have several pieces of documentation about libraries, but I am not yet able to infer what steps are needed to compile and deploy a library and then a contract that uses it. The behavior of the ...
24
votes
1answer
12k views

How does the delegatecall method work to call to another contract's method?

I'm trying to figure out how to use the delegatecall method on a contract address in a contract to call a function in a separate contract. I know Libraries are the higher level interface to use but I ...
15
votes
5answers
16k views

Is there a C# implementation available for Ethereum?

Is there a C# / .NET / Mono implementation available for Ethereum to interact with nodes and/or the blockchain?
10
votes
1answer
5k views

How to call a library contract

library ECVerify is deployed on 0x3bbb367afe5075e0461f535d6ed2a640822edb1c on the Ropsten test net. How do I call function ecverify(bytes32 hash, bytes sig, address signer) returns (bool) {} in that ...
10
votes
2answers
837 views

Solidity: accessing a library constant in a contract that imports the library

Is it possible to access a library constant in a contract that imports the library? I am using solidity 0.4.11 For instance: library Lib { bytes1 constant flag = 0x01 ... } separate file ...
9
votes
1answer
2k views

How to link libraries in browser-solidity? [duplicate]

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....
9
votes
1answer
3k views

Finding and Using Solidity Libraries (ie. Math functions)

How do I find and use any existing Solidity libraries like you might in Javascript? For example, Math functions: How do I implement the equivalent of Math.sqrt(x) in a solidity function? Related: ...
9
votes
2answers
2k views

Trying to understand libraries

I have a library which I want to deploy followed by a number of differing contracts which link to it. However I seem to me missing some understanding about library deployment and utilisation. The ...
9
votes
1answer
535 views

Finding and linking to libraries

Contracts\Libraries like ERC20 and SafeMath have probably been deployed many times to Ethereum. How do I find their addresses so I can reuse their logic instead of coping them and deploying them by ...
8
votes
1answer
446 views

How to handle library function prototype changes?

One great thing about using a library is that the library code can be modified, and as long as the api function prototype stays the same, all we need to do is point to the new address of the updated ...
8
votes
1answer
628 views

Are internal functions in libraries not covered by linking?

According to the documenation when using a library with internal functions, the function's bytecode gets inlined into the calling contract's function. Can someone confirm if the following is ...
7
votes
3answers
2k views

How to import solidity libraries in mix?

Working in the MIX environment, I'd like to try using a libraries and contracts defined in different files. However, the main contract always gets an error from MIX, no matter how I define the "...
6
votes
2answers
1k views

How to make a library address updatable

I want to write a contract that uses a library. This library should be exchangable. Meaning I want the contract to have an updatable (only by owner) address variable always pointing to the current ...
6
votes
1answer
2k views

How can I deploy a contract with reference to a library contract without using a graphical user interface like Browser Solidity?

I am using Solidity Browser to deploy a contract due to from Library contract method failing #2831 issue. On this following answer https://ethereum.stackexchange.com/a/9181/4575 I have guided to use ...
6
votes
1answer
668 views

Accessing calling contract storage in a library

I need to understand how is it possible to access the calling contract storage from library code. From Solidity manual: This means that if library functions are called, their code is executed in ...
5
votes
1answer
444 views

return (bytes32,bytes32) , returns actual transaction address instead of the real data

I have attached my contract, which works fine on populus and compiles on geth. It is a simple source code: Test() function appends data into my linkedlist that is defined in my library. And get() ...
5
votes
2answers
244 views

Sending ethers with mocha.js and truffle might result in larger sums than intended

Good day, I have a contract General and a library GenLib. library GenLib{ event MoneyIn (address _from, uint256 _amount); function moneyIn() { MoneyIn(msg.sender, msg.value); <- ...
4
votes
4answers
5k views

Ethereum library for iOS/Android?

Are there any existing native libraries (not whole wallets, I do not need a UI but want to sign transactions and call smart contract functions embedded in another app) for iOS or Android? If not, are ...
4
votes
1answer
456 views

How to access a mapping in a library?

library Lib{ struct Data { mapping (uint => uint) a; } function inc(Data self) internal{ self.a[0] =+1; } } contract Example{ address recipient = ...
4
votes
1answer
596 views

Using 2 libraries with a contract in a sol file

I have a sol file with a library and also a contract. The contract can use the library and everythings deploys correct using the solidity-browser. If I add a new library and call a function of that ...
4
votes
2answers
333 views

Usage of ENS for contract upgrade

Situation: let's assume we have a data storage contract libraries that import the data storage contract a business logic contract that implements the libraries Question: can we use ENS, or more ...
4
votes
1answer
959 views

(Sub) contract vs. library vs. struct vs. Interface

First I googled and read through these questions: Creating multiple contracts or Single contract with struct Child contract vs struct Why are so many examples using separated contracts (e.g. crowed ...
4
votes
1answer
317 views

Out of gas error deploying library

The following code is compiled with solc 0.3 with correct --libraries linking and deployed to morden. Math library is deployed just fine and can be accessed. However A doesn't get deployed on morden ...
4
votes
1answer
404 views

Watching events defined in libraries

Is it possible to watch for event triggers when the actual event and trigger is defined in a library? I get no console output with the following code library ObjectHistoryLib { event ...
4
votes
1answer
187 views

Is it possible to get an address of a struct in the Library or Contract without using mapping?

[Q] I was wondering is it possible to get an address of a struct on the memory space? Inside initialise() function after the Node object creation, I want to get is address if it is possible. Since ...
3
votes
1answer
1k views

Difference between library-using-for and contract-is

I am using two different ways to get the same result and wondering what the real difference is. Both options (library, using, for and contract, is)deliver just an extended code from a file. Method no ...
3
votes
1answer
212 views

Help to understand library linking and the multisig hack [duplicate]

Just read about the today issue with parity multisig wallets, https://paritytech.io/blog/security-alert.html where as far I can understand the problem is that a library linked to many wallets was ...
3
votes
1answer
202 views

Solidity events in libraries - not displaying correctly in Mist

Has anybody been successful in executing and viewing events (in Mist) generated from solidity libraries? My contract can log and display events in the contract but events in the associated libraries ...
3
votes
1answer
678 views

Linking contracts via library contract

The problem involves 3 contracts with an interdependence as follows: library --> ProductContract --> BillingContract The contracts are structured as follows: (The DataSet.sol contract below is ...
3
votes
0answers
194 views

Benefits of library versus a plain contract (upgradeability)

I'm trying to find what the benefit is of a library. I found the following statements. (Please correct me if i'm wrong) Cost less gas to deploy Uses the storage of the calling contract the library ...
3
votes
0answers
185 views

What is the runtime performance of Ethereum Libraries compared to Contracts?

I'm looking for the cheapest way (in terms of gas price) to design upgradeable contracts. I don't expect many upgrades. Being inspired by Writing upgradable contracts in Solidity, I'm investigating ...
2
votes
2answers
913 views

Is it possible for a smart contract to be able to adjust it's conditions based on the current value of Ethereum?

I ask this because I want to create a crowdfunding smart contract for a platform much like Kickstarter. At this point, the only crypto asset I want the contract to raise is Ether with the possibility ...
2
votes
1answer
89 views

How does a contract know which library to query or know the library address?

How does a contract know which library to query? For Example in the code below (The code is from solidity docs: https://solidity.readthedocs.io/en/v0.4.24/contracts.html?highlight=library#libraries ...
2
votes
1answer
1k views

(Solidity) Inheritance: how to add additional attributes to a struct in base contract?

This is a very simplified example but it of course extends to more complicated contracts too, I just haven't found an elegant solution. contract Group { struct Person { uint age; ...
2
votes
1answer
577 views

Is there a Solidity library for generating addresses?

I'm generating a few thousand addresses to test a contract, could I do that in Solidity, or do I have to use something like ethereumjs-lib ?
2
votes
2answers
509 views

How can I program my DApp to tell my user that their action/transaction has been confirmed?

Take an example of a voting DApp. A user clicks on a vote button, then behind the scenes the transaction containing the vote gets mined on the blockchain. The DApp then wants to alert('You have ...
2
votes
1answer
393 views

Verifying contracts with libraries

I have a problem very similar to this Cannot verify contracts with libraries on Etherscan Simple code pragma solidity ^0.4.16; //optimization enabled library C { function a() returns (address) { ...
2
votes
1answer
212 views

Need help with solidity library deployment

I have an issue with a simple library configuration and I need an advise to resolve this. Context: Local private block chain Version: > web3.version { api: "0.18.1", ethereum: "0x3f", ...
2
votes
1answer
533 views

How to use Library with 1 File on browser solidity?

I use browser solidity. Now, I wanna create this C Contract. But, I have a message "Deploying and liking required libraries" on the right side of the picture. I have already create Math Library, and ...
2
votes
0answers
22 views

Can I import a Library from a Library?

Is it possible to import a library into another library? I give a simplified example below of what I'd like to achieve: library structLib { struct Point { uint X; uint Y; } } ...
2
votes
0answers
89 views

Can I call a library function from a payable function?

I seem to get a revert each time I try this. I'm unable to get any useful revert message from truffle, so any assistance there might also help solve this. I have a library: library LibInterface { ....
2
votes
1answer
23 views

Why won't remix finish launching all of my libraries?

I've run into an issue. I have a contract with a hierarchy of libraries (some lower level libraries import higher level libraries). All libraries are ultimately imported by our main contract. ...
2
votes
0answers
43 views

Which solidity dev environments support the use of already deployed library contracts?

So, I'm looking into using libraries in order to prevent re-deployment/re-use of the same code. I was hoping that I would be able to specify the address of a library in solidity code, using syntax ...
2
votes
1answer
134 views

Library function overloading

I have 3 libraries, one exposes struct and 2 others expose method with same signature/return type (first one provides default method implementation and second - extended and customized one). When ...
2
votes
0answers
144 views

delegatecall on library always run out of gas

I'm trying to replicate the Dynamic Library attack of this paper under a recent version of solidity and the EVM. Streamlining down the code, I've created this very simple contract (which is, in ...
2
votes
0answers
106 views

Solidity libraries with public visibility

Suppose I have the following Contracts and a Library: pragma solidity ^0.4.21; library UserLib { function insertUser(address dbAddr, bytes32 user) public { DB(dbAddr).setUser(user); } } ...
2
votes
1answer
295 views

Is it possible to use a solidity library inside another?

I am trying to use a solidity library inside another. The minimal code would be something like this: The deepest library: SLib.sol pragma solidity ^0.4.18; library SLib { struct SCtx { uint a;...
2
votes
0answers
193 views

How to create a contract B that calls a library via contract A

As I understand it, the logic to deploy contract that uses library is as below: supposed that MetaCoin contract use TestLib library Deploy TestLib library first, then get a library contract address ...
2
votes
0answers
83 views

What's the value of `this` inside a library function when called via a delegatecall?

Imagine a contract C that makes a delegatecall to a library L. C -> L What's the value of this inside L: address(C) or address(L) ? If now that L makes a normal call to another contract D. C ->...
1
vote
2answers
507 views

SafeMath library vs SafeMath contract on the inheritance chain

guys, I am developing ERC-20 token and I am wondering why SafeMath is used as as library in the OpenZeppelin implementation? Will not it be more optimal if we supply it as a base contract on the ...