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.

Filter by
Sorted by
Tagged with
1
vote
0answers
15 views

solc 0.7.0 --allow-paths --base-path woes on (Version: 0.7.0+commit.9e61f92b.Linux.g++)

I have a library Foo.sol in /logicalroot/src/main/sol/lib/Foo.sol I have a contract MyContract in /logicalroot/src/main/sol/contracts/MyContract.sol That contract sources this: import {Foo} from "...
1
vote
1answer
15 views

Library calls fail depending on compiler version?

I'm trying to deploy my library and call it afterwards with the specific address. While testing this I encountered that the behavior changed over the course of compilers. I tried to follow How to call ...
0
votes
1answer
44 views

pass storage through interface to library

Here is what am i doing: There is a library, accept storage argument as parameter, then do some math and return the result. And there is a contract to call the function in the library, and an extra ...
3
votes
3answers
271 views

Publishing contracts with libraries using web3.py

Im trying to publish contracts with libraries in them and im getting the below issue. Contracts without libraries publish just fine. Can someone who might have faced this issue before advise what the ...
2
votes
1answer
37 views

Ethereum linking library with contract not working as accepted…returning any state variable returns just the default value

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

Library function access-level

I have a contract A, which has an instance of contract B, i.e., B b. Contract A calls a function of contract B via the instance, i.e., b.func(). Contract B is stateless, i.e., no global non-constant ...
0
votes
1answer
43 views

Link library to contract without migrations

To link library in migrations I use: await deployer.deploy(MyTokenL) await deployer.link(MyTokenL, MyToken) We want to use migrations as infrastructure deployment and then have a deployment factory ...
0
votes
1answer
23 views

When would one want to use a linked library?

My understanding is that if a smart contract consumes a library that only has internal functions, then the compiler will embed the library into the contract bytecode. At the lowest level, there is no ...
0
votes
1answer
24 views

Passing storage of one library to another library

I have two libraries: A and B as well as contract C using them. Library B, in one of its functions, needs to call a couple of functions defined for A.Storage. The code below compiles, tests are ...
0
votes
1answer
143 views

Contract libraries structure

I have pretty big smart contract with a lot of structs. Each struct has in average 3-4 related methods (i.e. methods with first parameter MyLibrary.MyType storage self). Question about code ...
2
votes
1answer
161 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 ...
3
votes
0answers
58 views

Unit testing a Solidity Library function with a struct memory argument

I am trying to unit test a Solidity Library contract function using truffle and web3. My simplified Library contract looks like this: pragma solidity >=0.5.16; pragma experimental ABIEncoderV2; ...
1
vote
1answer
34 views

Can 3rd party call public functions of Solidity library?

A library is deployed separately and a contract is linked to it. All internal library functions are copied to the contract using it. But what about public functions? If the library declares struct ...
1
vote
4answers
381 views

How to deploy Library contract separate from the main contract and link it

For deployment I am using remix. When I deploy Hello.sol the compiler typically merges SafeMath.sol as a part of the main contract (Hello.sol) and deploys. This adds up library and main contract's ...
2
votes
2answers
215 views

Is library use inherited?

When a base class uses a library, do derived classes also use the same library? For example: contract A { using SafeMath for uint256; ... } contract B is A { //is code here using ...
1
vote
1answer
35 views

How to use solidity library with truffle

I'm using truffle V5.1.13 and when I run truffle test the res variable contains a transaction receipt rather than the expected 2. I notice if I remove everything that has to do with the library things ...
0
votes
1answer
87 views

Searching for a value in a dynamic array

I understand that for loops on dynamic arrays are a big no no in Solidity, so I am trying to find an alternative to this problem. Goal: From a dynamic array of numbers, I am trying to extract the ...
1
vote
0answers
26 views

Truffle contract bytecode not updating with library address

After deploying a library using truffle, I want to compile a contract and use the library address inside its generated bytecode. Now inside the contract bytecode I get something like _DateTime______. ...
1
vote
1answer
326 views

implement solidity library with no overhead of external function calls

When reading the doc of Solidity.I found out that the following is hard to understand or maybe I misunderstood something, any help is much appreciated.The document says: The following example shows ...
0
votes
0answers
25 views

Could you add a contract address in place of a library address when editing the bytecode before deplyment?

After compiling a contract that uses a library it is necessary to go into the compile contract bytecode and remove a piece that looks something like "_________library__address______" and replace it ...
0
votes
0answers
16 views

Reference library in external contract

Say contract A {} uses function from library Math {}, can it reference the library from an external contract, and if yes how?
1
vote
0answers
74 views

Function selector computed differently for libraries?

As documented in various places, the function selector is computed as the first four bytes of the keccak256 hash of the function header, which consists of the function name followed by the list of ...
1
vote
0answers
39 views

Any C library available to interact with an Ethereum smart contract?

I need a C library that enables to create, sign transactions and interact with the smart contract.
0
votes
1answer
40 views

library modifying string vs string literal

I have a library which has the following function: function strConcat( string memory _a, string memory _b ) internal pure returns (string memory) My contract implements the library ...
0
votes
0answers
47 views

web3 - Can I call a library function without a contract?

I have a library which contains a function concat - it can merge two bytes. I have deployed a contract which uses that library and it works. I would like to make a simple bytes builder on my website. ...
11
votes
3answers
1k 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 ...
0
votes
1answer
90 views

Building Ethereum application with in-process client

Most applications connect to an Ethereum Node through RPC, using a library like Web3.js and Nethereum. That introduces a need to deploy a full node side-by-side with the application, be it on the ...
0
votes
1answer
275 views

Solidity modifiers in library?

Isn't it possible to define modifiers in libraries? I'm really asking myself why, because thats some functionality you would need over and over again. If I would like to hypothetically implement some ...
1
vote
1answer
80 views

unable to understand how to use internal function types

I need help to understand below code which is from solidity offical documents "how to use internal function types". as it is very confusing for me. How to use library in solidity. Some one explain ...
0
votes
1answer
39 views

Can a library use another library?

Is it possible to use a library within a library? library L2 { //... } library L1 { using L2 for *; //... } This compiles and runs just fine but what I really want to know is if L1 is ...
1
vote
0answers
108 views

getting error error TypeError: Member “isContract” not found or not visible after argument-dependent lookup in address payable

Using Solidity 0.4.17, I have defined a simple library at ./Addresses.sol function isContract(address _base) external pure returns(bool) { assembly { _r := gt(extcodesize(_base), 0) ...
2
votes
0answers
34 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; } } ...
10
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 ...
1
vote
1answer
73 views

Why does this function not need a require statement?

Why does the following function not need a require statment? function transferFrom(address from, address to, uint256 value) public returns (bool) { _allowed[from][msg.sender] = _allowed[from][...
29
votes
1answer
15k 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 ...
2
votes
0answers
55 views

Ethereum js wallet for php

https://github.com/ethereumjs/ethereumjs-wallet I need this library with the same functions in PHP Would u give me the link
16
votes
5answers
18k 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?
2
votes
0answers
106 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 { ....
0
votes
1answer
234 views

Trouble with libraries (Remix)

Tried out libraries for the first time, had a really bad experience with them. I need some help in getting my contracts to work between libraries. Library 1: pragma solidity ^0.4.0; library ...
1
vote
1answer
77 views

Using 3rd party libraries in production

In the case where you wish to use a library that someone else has written for your own contract, is it generally best practice to link to the developer's own deployment of their library? Or should you ...
11
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 ...
2
votes
1answer
37 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. ...
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 ...
2
votes
1answer
123 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 ...
1
vote
0answers
99 views

Understanding Solidity Libraries using Solidity Docs code example

I was going through this code (see code below) about how to use libraries in solidity docs : https://solidity.readthedocs.io/en/v0.4.24/contracts.html?highlight=library#libraries and there are some ...
2
votes
0answers
70 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 ...
0
votes
1answer
498 views

Unable to retrieve struct from mapping

I have a mapping like this: pragma solidity 0.4.24; pragma experimental ABIEncoderV2; pragma experimental "v0.5.0"; ... mapping(bytes32 => LibMarket.Market) public hashToMarket; where each ...
1
vote
0answers
241 views

How to verify a contract with libraries deployed from Remix

I successfully deployed a contract with remix here on Ropsten Testnet: https://ropsten.etherscan.io/address/0x10273a926517b417015748da21e1287bab2da8f7 The Source Code is very simple but I'm using my ...
0
votes
1answer
228 views

Solidity SafeMath library best practice use cases

I understand why and how to use the SafeMath library. However, I was wondering if there is a kind of best practice guide how and when to use the library and in which cases you don't have to. From a ...
4
votes
2answers
372 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 ...