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.
29
questions with no upvoted or accepted answers
4
votes
3answers
310 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 ...
3
votes
0answers
112 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;
...
3
votes
0answers
235 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
1answer
182 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 ...
3
votes
0answers
197 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
1answer
42 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 ...
2
votes
0answers
36 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
57 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
2
votes
0answers
110 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
0answers
81 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
173 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
199 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
58 views
Can paritytech/parity be used as a library the same way that go-ethereum can be used in Go?
The go-ethereum project is divided into a set of standalone libraries that can be used in any Go project (e.g. smart contract interaction, keystore management, common cryptography and hex utils)
Can ...
2
votes
0answers
126 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
0answers
200 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
91 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
0answers
28 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
0answers
34 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
0answers
100 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
40 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.
1
vote
0answers
168 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)
...
1
vote
0answers
111 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 ...
1
vote
0answers
263 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
0answers
29 views
Solidity Encoding Function Call With A Reference Parameter
I'm deploying an external library. This library will have a function that modifies a state variable of the calling contract.
I am accessing this library through a proxy contract that stores state. So, ...
0
votes
0answers
15 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 ...
0
votes
0answers
26 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
58 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. ...
0
votes
1answer
52 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 ...
0
votes
1answer
148 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 ...