question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data returns 0x0000... in contracts that use libraries that are created with `.new`

See original GitHub issue

Is there anything special to know about using MyContract.new(...) for contracts that use libraries? I’m having an issue where the deployed contract is working but a manual new does not properly link (specifically, data stored via the library, such as with the using ... for syntax, is coming back as 0x0000...).

This works:

// getData is a getter that retrieves data stored via a library
truffle(default)> MyContract.deployed().getData() // prints correct data

This returns 0x0000... for all values stored using the library:

// this should print the exact same data (different contract instance, but initialized the same way and same getter)
truffle(default)> MyContract.new().then(contract => contract.getData().then(console.log)) // prints 0x0000...

Unless I am missing something, this seems to be a bug. I can provide more details but I wanted to check first if I was missing something obvious.

Issue

Undeployed contracts are not linked properly.

Steps to Reproduce

  1. Deploy a contract that uses a library to store data
  2. Call a getter to see that data returns 0x0000...

(I can provide more details if necessary)

Expected Behavior

Expect data to be stored and retrieved successfully.

Actual Results

Data stored with library returns 0x0000... Data stored using the main contract without any library functions works fine.

Environment

  • Operating System: OSX El Capitan
  • Truffle version: 3.0.0-2
  • Ethereum client: TestRPC 3.0.0
  • node version: 6.1.0
  • npm version: 3.8.6

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
raineorshinecommented, Nov 14, 2016

Downgraded to v0.16.0. Works now.

Sorry this issue wandered from its original stated problem.

How should we proceed with documenting/identifying the 0.17.0-beta incompatibility? If it’s a web3 bug, just skipping 0.17.0-beta might be smart.

0reactions
raineorshinecommented, Nov 14, 2016

npm will not install 0.17.0-beta automatically if the specified version range is ^0.16.0, since the -beta is there.

truffle#beta specifies web3 ^0.16.0. truffle#beta specifies ether-pudding ^3.2.0. ether-pudding#0.16.0 specifies web3 ^0.15.3.

That’s all fine. I think the problem is that I am explicitly using web3 0.17.0-beta in my project. I guess there is a peer dependency to use the same version of web3 that is used by truffle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ConsenSys/truffle - Gitter
This returns 0x0000... for all values stored using the library: ... same way and same getter) truffle(default)> MyContract.new().then(contract => contract.
Read more >
Problem with create2 & linked library · Issue #8170 - GitHub
There seems to be a bug with the create2 operation: whenever I try to deploy any contract with linked libraries, the EVM reverts...
Read more >
Trying to understand libraries - solidity
Ok I've figured out what is happening. In a library the use of the internal accessor to a function will inline that function...
Read more >
HackPedia: 16 Solidity Hacks/Vulnerabilities, their Fixes and ...
Consider a malicious attacker creating the following contract, ... these libraries are used in Solidity, let us correct the TimeLock contract, using Open ......
Read more >
Solidity Documentation - Read the Docs
Solidity is an object-oriented, high-level language for implementing smart contracts. Smart contracts are programs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found