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
1 answer
58 views

Can anyone make this function of findMostOccurringString as transaction-less (view or pure)?

I want to make a utility contract (or more precisely a library) that can calculate the mode (max occurring) string from the given array of strings. Here's my approach for the same: //SPDX-License-...
user avatar
0 votes
0 answers
18 views

Why am I not able to call a pure function accessing an enum from a library?

I'm working on a token-gated NFT distribution site. I've divided up the 256 bits of the token id & I'm using various parts to represent different aspects of a permissioning system. Central to the ...
user avatar
  • 101
0 votes
0 answers
19 views

Deploy Contract that uses a Library with public functions

I had to split my contract into multiple smaller contracts due to Contract Size Limits. According to ethereum.org tutorials, Using a Library with public functions will reduce your contract size So I ...
user avatar
0 votes
1 answer
52 views

How do I pass a struct as an argument in delegatecall to a proxy library?

I am trying to call the buyAssetsForEth function in the OpenSeaMarketV2 library using delegatecall as follows: pragma solidity 0.8.4; contract Owned { address public owner; constructor(...
user avatar
0 votes
0 answers
46 views

ABDKMath64x64 function works in local brownie tests and remix kovan deployment, but transaction reverts when trying it on kovan testnet

Me and my team are quite dumbfounded by this issue we have with one of the utility functions we wrote in our contract that make use of the ABDK64x64 library, the code of which can be found below: In ...
user avatar
  • 1
0 votes
1 answer
20 views

Solidity return enum in library

library MyLib { enum MyEnum { A, B } function f() public pure returns (MyEnum){ return MyEnum.A; } } I want to return the enum in library. It is deployed as well, but ...
user avatar
  • 1
0 votes
1 answer
65 views

In Solidity, when invoking an external contract, how do you override its library functions using a separately deployed contract?

I am trying to understand how an exploit occurred on the Ethereum network as per PeckShield's Tweet. According to the exploit transaction logs, contract code at ...
user avatar
0 votes
0 answers
29 views

How to import struct members from Solidity Library

Trying to implement the diamond upgrade following Nick Mudge implementation in aave. Been getting this error (struct member not found or not visible after argument dependent lookup in struct) ...
user avatar
0 votes
1 answer
54 views

Can a library have a `public` function using `struct memory`?

I can't find any up-to-dates (and clear enough for my level of understanding) responses to this question that has also been raised very recently on a hardhat issue, with no response to date (https://...
user avatar
1 vote
1 answer
52 views

Why does this library method return 0?

Have this library method which I use several times in a contract, but in one specific function returns 0 even though I'm logging in the value generated in the library per se and checking that it does ...
user avatar
  • 307
0 votes
1 answer
43 views

Can we use Storage Keyword in solidity library?

I was reading about libraries and came to articles saying library cant have storage. But I have seen libraries where storage keyword has been used. Example: in Aave protocol v3 function ...
user avatar
  • 363
0 votes
0 answers
5 views

Is there a way to cache libraries in dapptools?

Can dapptools cache libraries instead of deploying them every time I need to use them for a build or a test?
user avatar
0 votes
1 answer
59 views

Brownie having different behavior for library dependencies

When I use my custom library, Brownie complains that the library is not deployed (UndeployedLibrary). But why doesn't it complain about other library files like the ones inside OpenZeppelin? For ...
user avatar
  • 3
0 votes
1 answer
47 views

How can I use a library to create a common enum and struct between two contracts?

Here is what I'm trying to do by using a common enum and struct between two contracts: Library Code: pragma solidity ^0.8.7; library Library { enum Areas { Burrow, School, Forest, Mine, DeepMine, ...
user avatar
1 vote
1 answer
220 views

How does Bytes-Utils slice function work?

I'm quite confused of how the bytes-utils library's slice function. I have a few questions about how it works, especially about the code below. The full code can be found here. Why is tempBytes ...
user avatar
  • 13
1 vote
1 answer
182 views

Uniswap V2: TypeError: Explicit type conversion not allowed from "int_const -1" to "uint256"

I was trying to fork Uniswap V2 with another protocole and ran into this error while compiling the contracts: TypeError: Explicit type conversion not allowed from "int_const -1" to "...
user avatar
  • 103
0 votes
0 answers
40 views

calling functions from deployed library

Suppose I have the follow Library deployed at Address A library aLibrary { address constant owner = //AddressB; function customSend(uint256 value, address receiver) public returns (bool) { ...
user avatar
  • 121
0 votes
1 answer
708 views

Why is there significant gas costs associated with call and delegate call?

I've been trying to understanding why Ethereum doesn't have a significant on chain package/library ecosystem despite having the capacity to do so via delegatecall or call to an ImplementationContract ...
user avatar
  • 230
1 vote
1 answer
467 views

Need help reducing contract size for ERC721Upgradeable Proxy Contract

I'm unable to compile my proxy contract due to Warning: Contract code size exceeds 24576 bytes If the implementation logic is written inside the main MyNFT.sol proxy contract, won't the Proxy contract ...
user avatar
  • 111
0 votes
0 answers
48 views

How to Link Deployed Library

I want to use a library that has been deployed, and I already know the address. Therefore, my contract should be linked to that library. However, I'm not supposed to deploy my library instance ...
user avatar
  • 1
0 votes
1 answer
97 views

How to use a library contract function inside my contract without inheriting

I have a library contract deployed on ropsten with address 0xc0b843678E1E73c090De725Ee1Af6a9F728E2C47 and code // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; library ...
user avatar
1 vote
1 answer
84 views

How to reference an already deployed library function ONLY using the deployed address?

I've been trying to find a way to reference an already deployed library via address IN Solidity code, and couldn't find one, nor could find any explanation on whether this is even possible. For ...
user avatar
  • 441
0 votes
1 answer
182 views

smart contract how link libraries to child contract under factory pattern

I am trying to create a factory and I can not find a way to link libraries to the child contract. I am trying to create a contract factory that create child contracts. the problem is that the child ...
user avatar
0 votes
1 answer
241 views

What is the purpose of OpenZeppelin ECDSA.sol contract?

what is the purpose of the ECDSA contract ( https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol ) ? Contract looks like a wrapper around builtin ...
user avatar
  • 101
1 vote
0 answers
339 views

Why don't we have an EVM integration library written in C++?

We have web3.js for JavaScript, web3j for Java and NEthereum for Unity/.NET. I want to develop with Unreal Engine (C++) a game that runs on Polygon, but there's no integration library in C++. Should I ...
user avatar
0 votes
1 answer
138 views

Who is the msg.sender when a library makes a call()

I have a library that is making a call to an external address like this externalAddress.call(callData) This callData is calling a function of another contract that is utilizing the msg.sender value. ...
user avatar
2 votes
2 answers
1k views

How can I reference a deployed library in my solidity contract

Suppose I have a contract that uses a library, which has already been deployed to the blockchain at a certain address. Is there a way to reference that deployed library in the contract similar to ...
user avatar
  • 189
0 votes
0 answers
26 views

TickMath UniswapV3 library. Trying to understand getSqrtRatioAtTick solidity function inside

Please, I am uncapable of understanding the logic behind getSqrtRatioAtTick function. Is there anyone wise/clever enough for explaining for example this line? if (absTick & 0x4 != 0) ratio = (...
user avatar
1 vote
2 answers
221 views

Why can I use Linked Libraries on Remix IDE without deploying them first?

I'm trying to understand the differences between Linked Libraries and Embedded Libraries. I already read some articles and watched these tutorials: https://www.youtube.com/watch?v=25MLAnIzXRw https://...
user avatar
0 votes
1 answer
197 views

Hi, I need to add the library address (0x.. exc.) of the url below.. Where can I find It?

I need to add the library address (0x.. exc.) of the following url .. Where can I find It? https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol
user avatar
1 vote
1 answer
190 views

How to input key-value pairs into a constant mapping in a library in solidity?

How can I input key-value pairs into foo? Is there something like below that can be done? library abc { mapping(int256 => int256) internal constant foo = {1: 10, 2: 20, ...}; \\ rest of ...
user avatar
1 vote
0 answers
147 views

Query ethereum from C++

I was wondering if its possible (essentially if there exists a library) to query a node (either IPC or RPC) on ethereum. For example there is web3(py,js), there is ethereum in golang and probably ...
user avatar
  • 105
1 vote
0 answers
82 views

Alias for external library type?

Say you're importing a library, and that library contains a struct: pragma solidity >=0.8.0; library SomeLibrary { struct FooType { uint256 value; } } contract SomeContract { ....
user avatar
3 votes
2 answers
176 views

Link a library to a smart contract only with Solidity and bytecode

I work in Truffle development environment and use Windows PowerShell. My Solidity code is a test code and is simple. There is a library called Alireza that just compares two uint values. There is a ...
user avatar
  • 375
0 votes
0 answers
23 views

Using functions from a library

I'm working on a Dapp for voting in a municipality and national election. There is a lot of code, and I've met the max limit of the contract size many times but have been able to keep it under the ...
user avatar
  • 1
0 votes
1 answer
148 views

Are calls to internal pure functions cached by Solidity?

One of my library functions calls another internal pure function like this: library MyLibrary { function foo(uint256 x) internal pure returns (uint256 result) { // do important work } ...
user avatar
1 vote
0 answers
77 views

Mapping shared between contracts

I have enums that I use in many contracts of one project. Sometimes, they need to be mapped to a uint256. Their uint256 values do not relate to their positions in the enum list, so I can't just cast ...
user avatar
  • 376
2 votes
1 answer
427 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 "...
user avatar
1 vote
1 answer
70 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 ...
user avatar
  • 23
0 votes
1 answer
104 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 ...
user avatar
0 votes
1 answer
221 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 ...
user avatar
  • 157
5 votes
0 answers
891 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; ...
user avatar
  • 149
1 vote
1 answer
443 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 ...
user avatar
  • 157
1 vote
1 answer
413 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 ...
user avatar
  • 360
0 votes
1 answer
831 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 ...
user avatar
  • 291
1 vote
0 answers
88 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______. ...
user avatar
  • 11
0 votes
0 answers
36 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 ...
user avatar
1 vote
0 answers
428 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 ...
user avatar
  • 145
1 vote
0 answers
63 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.
user avatar
  • 85
0 votes
1 answer
404 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 ...
user avatar
  • 641