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
15 views

How works refund ReentrancyGuard library for solidity

When I was reading the library code, I came across the following comment: "the values being non-zero value makes deployment a bit more expensive, but in exchange the refund on every call to ...
TabFoxOne's user avatar
0 votes
0 answers
10 views

How to Retrieve Library Addresses Linked to a Smart Contract on Etherscan?

I've run into a situation where I need to identify the library addresses that a verified contract is linked to. I understand that during the contract verification process on Etherscan, one must ...
MShakeG's user avatar
  • 1,443
0 votes
0 answers
7 views

Would this library be interesting to dApp developers for in-browser wallet?

I'm with INTMAX, developing webmax.js, a JS library for quick dApp integration with our in-browser web3 wallet that's secure, uses biometric authentication, & supports EVM-compatible / Layer 2 ...
popomint's user avatar
0 votes
1 answer
29 views

Use of { } when importing libraries?

Can anybody tell me the exact use of { } in import/require library statements? I've seen some other questions where people said it's to import just a part of a library, let's say the 'ethers' part of ...
Andy's user avatar
  • 185
2 votes
1 answer
172 views

Does Foundry Support Dynamical Library Linking in Solidity?

I would like to deploy a contract that has external library dependencies that need to be dynamically linked. This is typically done in hardhat ethers as follows: const MyLibrary = await ethers....
MShakeG's user avatar
  • 1,443
0 votes
0 answers
45 views

Explicitly linked Solidity libraries produce bigger contract size than having it embedded

If I replace all the library functions' visibility to either external or public, I will have to deploy the libraries separately first, and then explicitly link them in the contract which is using them....
user2340939's user avatar
0 votes
1 answer
22 views

Differences between function visibility features in Libraries

Function visibility in Libraries seems to provide different set of features than in ordinary contracts. I think that also depends on the library type - if it is externally deployed or if it's code is ...
lqzic's user avatar
  • 1
0 votes
2 answers
823 views

How to link a library to a smart contract using Foundry [duplicate]

I am using Foundry https://book.getfoundry.sh/ and wanted to deploy a library having external methods and link it to a contract before deploying it. Can someone share any docs or a simple example of ...
Sudhanshu's user avatar
0 votes
0 answers
10 views

I am looking for resources to research on how to create a library that interacts with the blockchain (ether js like)

I know it's complex, and I know it's extremely hard, but I just want to take a look at how things are created. I want to create a library that interacts with the blockchain exactly the way ethers js ...
Mohamed Ashraf's user avatar
0 votes
0 answers
65 views

Unable to use a function from imported library

I'm trying to import and use a library to verify ring signatures. On doing so I'm getting an error while loading smart contract using w3.eth.contract(abi=abi, bytecode=bytecode). ValueError at /sc/...
P S's user avatar
  • 101
2 votes
0 answers
336 views

How to deploy a contract with linked libraries and a different version in `foundry test`

I need to deploy a contract with an incompatible version number to my test script. The natural solution is to use deployCode, however, this contract also requires certain libraries. The following ...
Peteris's user avatar
  • 1,005
0 votes
2 answers
132 views

If a solidity library function is marked as public does it inline the function or call it with a delegatecall from the calling contract?

I am aware that a solidity library function marked as external will be deployed separately and called with delegatecall from the calling contract. Whereas a function marked as internal will just be ...
FreddyC's user avatar
  • 181
1 vote
1 answer
108 views

Free functions vs Libraries

From solidity docs: Free functions are always internal functions and are meant to replace internal library functions and their very special behaviour. How do free functions differ from libraries? ...
Ryan Sea's user avatar
  • 608
0 votes
1 answer
76 views

Atomic swap solidity library

Is there a production-ready atomic swap library to be used in solidity? This would be needed to implement the EVM part of an atomic swap protocol
mr_bovo's user avatar
1 vote
2 answers
249 views

Define a struct in library vs in the contract

I have a struct defined in a library (to call it from different contracts): library DataTypes { struct Test{ uint256 a; uint256 b; } when i want to initialize it or update in my ...
noro meb's user avatar
  • 328
2 votes
1 answer
734 views

Can not use sendValue method of Address library provided by Openzeppelin

I was trying to use Openzeppelin Address library sendValue(), and it kept showing error Member "sendValue" not found or not visible after argument-dependent lookup in address.solidity(9582) ...
Ray's user avatar
  • 123
1 vote
2 answers
48 views

Why is the function external in the following solidity script?

Came across this script teaching people how to use library, but I don't understand why the function testFind should be external in the following script. The definition of external function is : ...
Simon Zhao's user avatar
3 votes
2 answers
2k views

How to deploy a contract and a library together using HardHat

Suppose I have a contract named MetaCoin.sol // SPDX-License-Identifier: MIT // Tells the Solidity compiler to compile only from v0.8.13 to v0.9.0 pragma solidity ^0.8.13; import "./ConvertLib....
Nitesh Sawant's user avatar
1 vote
0 answers
18 views

Safety of writing fund transfer and NFT transfer code in an externally linked library

If suppose there is a main contract A that is linked to an external library L, would it be safe to move all the fund transfer and NFT transfer calls from the main contract into the library to reduce ...
Sheeshco's user avatar
0 votes
2 answers
24 views

How to make a delegatecall to a already deployed library of which you have the address

The below code fails when calling foo() on TestContract. The adaptedLib as been set to the right address. How do you make a delegatecall to a lib correctly? contract TestContract { address public ...
FreddyC's user avatar
  • 181
0 votes
0 answers
32 views

Low level delegatecall to a lib does not change state in calling contract

In the code bellow when calling foo the storage of TestContract gets not changed. Expected behaviour to my understanding is that state.a is set to 5. The arg passed to the library function foo is a ...
FreddyC's user avatar
  • 181
0 votes
2 answers
123 views

How to link deployed library to contract in brownie?

As far as I know, brownie automatically links the library to contract. Is there a way to do this manually? I have bunch of contracts in different projects where some use library and some don't. So I ...
Emrah's user avatar
  • 1,564
0 votes
1 answer
8 views

Large Size Disparity Between Contract and Its Library Wrapper

I have this contract called Pool.sol, and an external library for deploying it: pragma solidity ^0.8.0; // Contracts import "../Pool.sol"; library DeployerOfPools { function deployPool(...
mermeladeK's user avatar
6 votes
2 answers
796 views

Should I use Embedded Library (Internal) or Linked Library (External) to save gas?

I am aware that in solidity there are two types of libraries. Embedded Library: If a smart contract is consuming a library which have only internal functions than EVM simply embeds library into the ...
Sky's user avatar
  • 2,204
1 vote
2 answers
380 views

hardhat: want to test an emit event that is in a library

file Library library Events { error Mint(); } file Contract calling the event emit Event.Mint() Can't get Chai detect the event that is in the library Throw this error in both cases: ...
Tomis's user avatar
  • 11
0 votes
1 answer
119 views

Can libraries be forced to receive ETH as the recipient of another contract's selfdestruct() or as the miner reward?

At the end of the Libraries section in the Solidity docs, it says that libraries cannot receiver Ether: In comparison to contracts, libraries are restricted in the following ways: they cannot have ...
RSW's user avatar
  • 139
0 votes
1 answer
86 views

Possibility of a reentrancy attack when sending funds through a libraries external function

I want to know if this code is susceptible to a reentrancy attack. I am deploying a contract A that holds a certain amount of funds. I have added a function that calls upon a linked library and I have ...
Sheeshco's user avatar
0 votes
0 answers
74 views

Access shared library and other contract's functions

I have Contract A, Contract NFT, and Library. Library will have some NFT info that both Contract A and NFT needs. NFT contract has the following: contract NFT is ERC1155 { mapping(string => Library....
hammies's user avatar
  • 105
2 votes
1 answer
117 views

Linked library vs. standalone contract

What is the benefit of a linked library over a standalone contract? Let's say I want to reuse code between multiple contracts. The code itself has no state. Example library: library SafeMath { ...
Daniel Gretzke's user avatar
1 vote
1 answer
65 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-...
SYED ASAD KAZMI's user avatar
0 votes
0 answers
27 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 ...
dysbulic's user avatar
  • 101
0 votes
1 answer
653 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(...
Mr.Snow's user avatar
  • 13
0 votes
1 answer
104 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 ...
nate's user avatar
  • 1
0 votes
1 answer
147 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 ...
geniustree's user avatar
1 vote
1 answer
263 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) ...
Charles Okaformbah's user avatar
1 vote
1 answer
238 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://...
ClementWalter's user avatar
1 vote
1 answer
262 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 ...
dNyrM's user avatar
  • 713
0 votes
1 answer
582 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 ...
Mr.SsS's user avatar
  • 415
0 votes
1 answer
156 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 ...
SSgumS's user avatar
  • 13
0 votes
1 answer
346 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, ...
ohShoes's user avatar
  • 53
1 vote
1 answer
1k 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 ...
cpix's user avatar
  • 23
1 vote
1 answer
468 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 "...
Cizia's user avatar
  • 233
4 votes
2 answers
3k 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 ...
MShakeG's user avatar
  • 1,443
1 vote
1 answer
857 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 ...
626's user avatar
  • 111
0 votes
1 answer
464 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 ...
Ashish kumar's user avatar
2 votes
1 answer
306 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 ...
Vlad's user avatar
  • 501
1 vote
1 answer
397 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 ...
GrailsBeginner98's user avatar
0 votes
1 answer
648 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 ...
alex's user avatar
  • 101
1 vote
0 answers
681 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 ...
monkjuice's user avatar
0 votes
1 answer
481 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. ...
MoonGusto's user avatar