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
0
votes
1answer
17 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 ...
0
votes
1answer
18 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 ...
0
votes
1answer
27 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 ...
0
votes
1answer
65 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 ...
1
vote
0answers
47 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 ...
0
votes
0answers
41 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. ...
1
vote
2answers
169 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 ...
0
votes
0answers
15 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 = (...
0
votes
0answers
22 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://...
0
votes
1answer
35 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
1
vote
1answer
81 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 ...
1
vote
0answers
91 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 ...
1
vote
0answers
29 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 { ....
3
votes
2answers
81 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 ...
0
votes
0answers
23 views

Use ERC165Checker library function in web3

As I understand the ERC165Checker library provides the _supportsInterface function which takes a contract address and an interfaceId and returns whether that contract has the specific functions. How ...
0
votes
0answers
46 views

How to make a deployer in truffle tests?

For some reason, our app will only work with a forked instance of the mainnet. And hence, we want to run our test on the forked ganache. We are using truffle, so we have written all of our tests in ...
0
votes
0answers
21 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 ...
0
votes
1answer
62 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 } ...
0
votes
0answers
201 views

how to get the full list of block reward for the last 24 hours? Either via an API/JSON or Google BigQuery

I have spend a couple of days now trying to find a good source for the block rewards that will allow me to calculate block rewards and averages for the last 24h and since UTC0. (I am aware of being ...
1
vote
0answers
48 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 ...
2
votes
1answer
232 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
32 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
45 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
114 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 ...
4
votes
0answers
544 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
184 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
1answer
242 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
572 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
74 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______. ...
0
votes
0answers
31 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 ...
1
vote
0answers
233 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
44 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
135 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
178 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. ...
2
votes
4answers
2k 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
1answer
65 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 ...
0
votes
1answer
160 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
762 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 ...
0
votes
1answer
65 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
46 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
470 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
45 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; } } ...
1
vote
1answer
147 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 ...
1
vote
1answer
106 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][...
2
votes
0answers
61 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
5
votes
4answers
667 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 ...
2
votes
0answers
160 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
79 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
1answer
154 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
158 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 ...