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
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
121 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
1answer
496 views

Is it possible to use a solidity library inside another?

I am trying to use a solidity library inside another. The minimal code would be something like this: The deepest library: SLib.sol pragma solidity ^0.4.18; library SLib { struct SCtx { uint a;...
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
90 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
2answers
589 views

SafeMath library vs SafeMath contract on the inheritance chain

guys, I am developing ERC-20 token and I am wondering why SafeMath is used as as library in the OpenZeppelin implementation? Will not it be more optimal if we supply it as a base contract on the ...
1
vote
4answers
310 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 ...
1
vote
2answers
1k views

Can I define global variables in Library contract?

I want to use some variables in multiple functions in my library contract. Is there any way to do that? I got following error code for my library code. library myArithmetic { bytes1[10] mData; ...
1
vote
2answers
909 views

@dev and @title in solidity [duplicate]

When we use built-in library in solidity smart contract, why we need to use @dev and @title annotation? My code is like below: /** *@title SafeMath *@dev Math operations with safety checks that ...
1
vote
1answer
459 views

Reputable Solidity utils library for arrays

Is there an audited and reputable smart contracts utils library with helpers for dealing with arrays? I haven't found anything great on Google so far.
1
vote
1answer
105 views

Is there an Ethereum javascript library to work with creating and validating addresses?

There are a bunch of ethereum sites with alot of js functionality already, but how did they do this when there is no js library that I can find? Is there a javascript library for working with Ethereum?...
1
vote
1answer
29 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
77 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
70 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][...
1
vote
1answer
481 views

Using a library to change storage

I'm trying to learn about using libraries in solidity. In the following test contract, swapNumberLib does not successfully set value1 = value2. I thought libraries could act on the storage of a ...
1
vote
1answer
380 views

Library gets automatically included in contract

environment: all contracts use pragma solidity ^0.4.17; the compiler is 0.4.18+commit.9cf6e910.Emscripten.clang OS is MacOS X My token contract uses a Math library that is defined like so library ...
1
vote
1answer
1k views

link libraries with smart contracts

I have created library and imported in my contract. I am not able to link the library in deployment file. solution needed. thanks in adv pragma solidity ^0.4.2; library StringUtils { /// @dev ...
1
vote
1answer
503 views

Importing a contract from GitHub

I'm trying to import a contract from GitHub: pragma solidity ^0.4.18; pragma experimental ABIEncoderV2; pragma experimental "v0.5.0"; import "github.com/ethereum/dapp-bin/library/stringUtils.sol"; ...
1
vote
1answer
289 views

Solidity Library call gives Member not found or not visible after argument-dependent lookup

Using Solidity 0.4.17, I have defined a simple library at ./StringUtils.sol library StringUtils { function isEmptyString(string s) external pure returns (bool) { return (keccak256(s) == ...
1
vote
1answer
52 views

`vendor/` sub-directory relationship to 3rd party dependencies

In the -go-ethereum client directory I've run the command find . -name \*.md -print looking for README.md files. The output is as follows: ./.github/CONTRIBUTING.md ./.github/ISSUE_TEMPLATE....
1
vote
1answer
313 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 ...
1
vote
1answer
28 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 ...
1
vote
0answers
19 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
58 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.
1
vote
0answers
53 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
1
vote
0answers
87 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
236 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 ...
1
vote
1answer
76 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 ...
1
vote
0answers
28 views

How to import libraries to Mist? [duplicate]

I've create a contract in Remix imporing 2 differents libreries and it works ok, but when I copy and paste it into Mist I got an error at the import statement. Code goes like this: pragma solidity ^...
1
vote
1answer
107 views

library, not found or visible after argument-dependent lookup in type

I am trying to understand libraries and I keep running in to "not found or visible after argument-dependent lookup in type". pragma solidity ^0.4.17; library L{ struct S{ uint UI; } ...
1
vote
1answer
76 views

How do types inherit from libraries?

When you're using a library like SafeMath, and then have using SafeMath for uint256; within a contract, how do uints know to become the a parameter of the library functions? Is that just a convention ...
1
vote
1answer
596 views

Is there something like bitcore for Ethereum?

In Bitcoin there is a library named Bitcore. It helps abstract away a number of details, including using direct RPC commands. Is there something like Bitcore for Ethereum? Or do I need to use JSON-...
0
votes
1answer
453 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 ...
0
votes
1answer
39 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
1answer
239 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
2answers
888 views

How does solidity online compiler link libraries?

Suppose I have this code: import "github.com/Arachnid/solidity-stringutils/strings.sol"; contract Contract { using strings for *; // ... } For this solidity online compiler generates this ...
0
votes
1answer
54 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 ...
0
votes
1answer
148 views

Payable function 'charges' sender twice value sent in tx after invoking library function

Facing a nasty bug and could really use a pair of fresh eyes. I have a payable function that is somehow taking twice the value sent to it by the sender, from the sender. Specifically, it appears to ...
0
votes
1answer
20 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
37 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 ...
0
votes
1answer
216 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 ...
0
votes
1answer
376 views

Error: invalid solidity type!: (library.enum)

Consider the following sample Truffle project: . ├── contracts │   ├── Foo.sol │   └── Migrations.sol ├── migrations │   ├── 1_initial_migration.js │   └── 2_foo.js ├── test │   └── Foo.test.js └── ...
0
votes
1answer
89 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
31 views

Workaround for testRPC bug where amounts spent multiple time with library calls?

Using testRPC the amount transferred is multiple times of the msg.value if a library call is involved. There is bug report and it was raised here and here as well. It's a well documented, long ...
0
votes
2answers
789 views

How would you install the Ethminer without sudo access?

I am trying to get Genoil's Ethminer installed on a machine without sudo access. The Github instructions require some packages to be installed. sudo apt-get install git cmake libcryptopp-dev ...
0
votes
1answer
96 views

Modifer Inheritance, Unexpected Result

The setup of the contracts has 3 contracts: a library contract, a Controller contract with modifiers and a main contract as follows: DataSet.sol library DataSet { struct IndexValue { uint ...
0
votes
0answers
25 views

Types in Solidity [closed]

I have uint256 number. I need transform this number in binary or string format for my goal. What is restrictions in transfor and work with present formats exist in Solidity? What is the libraries ...
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
15 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?