Skip to main content
33 votes
Accepted

What are the steps to compile and deploy a library in Solidity?

First, let's save both of those files in the same directory and run solc --optimize --bin MetaCoin.sol. The output is: ======= MetaCoin ======= Binary: ...
redsquirrel's user avatar
27 votes
Accepted

How does the delegatecall method work to call to another contract's method?

Here is a snippet of D using delegatecall on E from Difference between CALL, CALLCODE and DELEGATECALL contract D { uint public n; address public sender; function delegatecallSetN(address _e, ...
eth's user avatar
  • 86.1k
15 votes

What are the steps to compile and deploy a library in Solidity?

To add, it's possible to manually link contracts (if you wish to deploy both library and contract together.) The simplest way is just to replace all occurrences of the placeholders with the address. ...
Matthew Schmidt's user avatar
10 votes

How to link libraries in browser-solidity?

Browser-solidity is able to import library code from GitHub (importing from Swarm is on the way). E.g. you can write: pragma solidity ^0.4.0; import "github.com/ethereum/dapp-bin/library/stringUtils....
max taldykin's user avatar
  • 2,966
10 votes
Accepted

How to call a library contract

A library is similar to a contract and you can use an abstract contract to declare its interface and then invoke (like Calling function from deployed contract). contract ECVerify { function ...
eth's user avatar
  • 86.1k
10 votes
Accepted

Solidity modifiers in library?

Library may define and use modifiers, but it cannot export them. Modifiers are compile-time feature, kind of macros. Modifier code is substituted by compiler to every method that uses this modifier. ...
Mikhail Vladimirov's user avatar
9 votes
Accepted

Finding and Using Solidity Libraries (ie. Math functions)

Currently the standard library isn't fully set up yet, but in this case what you would do would be to link your contracts to your library's address (and hopefully map it to a named registration in ...
VoR0220's user avatar
  • 1,710
9 votes
Accepted

Trying to understand libraries

Ok I've figured out what is happening. In a library the use of the internal accessor to a function will inline that function into the calling contract's bytecode. In my contract, all my library ...
o0ragman0o's user avatar
  • 4,330
7 votes
Accepted

(Solidity) Inheritance: how to add additional attributes to a struct in base contract?

I see where you're going with this and why the struggle. In summary, inheritance isn't going to work out with this approach. The fundamental thing is the structs and mappings (etc) forever define the ...
Rob Hitchens's user avatar
  • 55.4k
7 votes
Accepted

Difference between library-using-for and contract-is

In the first instance your contract is inheriting from the TestLibrary contract, and therefore you can perform the operation with increment(_base) or super.increment(_base). Additionally, if the ...
AndyK's user avatar
  • 695
6 votes
Accepted

return (bytes32,bytes32) , returns actual transaction address instead of the real data

You want to use link.call.get() Also, a better way to do it is just to mark the get function constant. Then it will do a call by default. This does a simulated transaction call and returns the ...
Tjaden Hess's user avatar
  • 37.2k
6 votes
Accepted

How to make a library address updatable

Here's a sketch of a way to do it, but be warned this isn't for the faint of heart. Create a base contract with a global variable that will point to the current library. Create the contract (the host)...
Matthew Schmidt's user avatar
6 votes

Solidity: accessing a library constant in a contract that imports the library

Since Solidity 0.6.2 it's possible to access it directly as <LibraryName>.<constant>: // SPDX-License-Identifier: GPL-3.0 pragma solidity 0.6.2; library Lib { bytes1 constant flag = ...
user8977154's user avatar
6 votes

Unable to retrieve struct from mapping

Since the error message is saying there are 5 results coming from the right-hand side of the assignment, that implies that the function hashToMarket() is not returning a Market object, but it's ...
MidnightLightning's user avatar
5 votes

Are internal functions in libraries not covered by linking?

You are indeed correct. Plugging this code into Remix, and looking at the disassembly gives: .code PUSH 60 contract Consumer {\n functi... PUSH 40 contract Consumer {\n ...
James_pic's user avatar
  • 1,110
5 votes
Accepted

How can I deploy a contract with reference to a library contract without using a graphical user interface like Browser Solidity?

Summary To deploy your library and contract code using geth, you will have to: Deploy your LinkedList library code and note the address it is deployed to. Replace the __LinkedList___...___ text in ...
BokkyPooBah's user avatar
  • 40.3k
5 votes
Accepted

How to access a mapping in a library?

Have your code changed as below function inc(Data storage self) internal{ self.a[0]=+1; } Note the storage part of it. Please understand the concepts of Internal Types for variables and ...
Abhiram mishra's user avatar
5 votes
Accepted

Ethereum library for iOS/Android?

There are some guys who are running geth on Android and iOS. you could find the libs and the apk project. But seriously, you need to wait the light protocol client because it is a bit insane to use a ...
Ellis's user avatar
  • 2,354
5 votes

Solidity: accessing a library constant in a contract that imports the library

Try pragma solidity ^0.4.7; library lib { bytes1 public constant flag = 0x01; function g() constant returns (bytes1){ return flag; } } contract test { bytes1 x = lib.g(); }
Badr Bellaj's user avatar
  • 18.8k
5 votes
Accepted

(Sub) contract vs. library vs. struct vs. Interface

There are two separate reasons you would want to separate your logic into more than one contracts / libraries / etc. 1- Modularity, ease of use, ease of maintenance. If you forgo the usage of ...
pabloruiz55's user avatar
  • 7,676
5 votes
Accepted

@dev and @title in solidity

See the Solidity Natural Specification (NatSpec) format github for details Solidity contracts can have a special form of comments that form the basis of the Ethereum Natural Specification Format. ...
TC8's user avatar
  • 1,260
5 votes
Accepted

SafeMath library vs SafeMath contract on the inheritance chain

SafeMath's functions are all declared as internal. That means that the library doesn't actually have to be deployed, as the functions are 'inlined' by the compiler: their code is just copied from the ...
Henk's user avatar
  • 4,281
5 votes

Is library use inherited?

No. In Solidity 0.7.0 and later versions, the effect of using ... for is no longer inherited. Quoting from the 0.7.0 changelog: using A for B only affects the contract it is mentioned in. Previously, ...
Samuel Peter's user avatar
5 votes
Accepted

How to deploy Library contract separate from the main contract and link it

It seems that Remix does this automatically. Library code: pragma solidity ^0.5.10; library Foo { struct F { uint256 x; } function foo (F storage f) external { f.x = ...
Mikhail Vladimirov's user avatar
5 votes
Accepted

Can not use sendValue method of Address library provided by Openzeppelin

This is really interesting. Notice how the sendValue first parameter is of type address payable while the isContract first parameter is only of type address. There is a difference. You just need to ...
Jeremy Then's user avatar
  • 4,619
4 votes

Using 2 libraries with a contract in a sol file

Found the issue. Do not use underscore characters when naming a solidity library as the solidity linker cannot process this character correctly during deployment.
Alex Darby's user avatar
4 votes

Is there a C# implementation available for Ethereum?

Microsoft came up with plugin for smart contract development using Solidity in Visual Studio. https://visualstudiogallery.msdn.microsoft.com/96221853-33c4-4531-bdd5-d2ea5acc4799/ You can develop ...
RaisKazi's user avatar
  • 159
4 votes
Accepted

How to import solidity libraries in mix?

So it turns out there is an issue in the current release...they have been notified. The work around is to use the full path. I also didn't realize that the full path is case sensitive.
Walt D's user avatar
  • 391
4 votes
Accepted

Finding and linking to libraries

Deploying duplicate code is wasteful, and what you want is completely reasonable. At the moment, there is realistically no way to achieve this. You could compare the bytecode of all deployed ...
Thomas Clowes's user avatar
4 votes
Accepted

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

The answer isn't straightforward, one is not necessarily better than the other Embedded libraries will be more expensive to deploy, since the code is being included with every contract deployment, but ...
natewelch_'s user avatar
  • 12.2k

Only top scored, non community-wiki answers of a minimum length are eligible