1

I'm trying to get my Contract to interface with the already-deployed CryptoPunksMarket Contract, seen here:

https://etherscan.io/address/0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb#code

Specifically, I only need to access the punkIndexToAddress public mapping which that contract declares, as follows:

mapping (uint => address) public punkIndexToAddress;

My own Solidity contract references this CryptoPunksMarket contract as follows:

pragma solidity >=0.4.1 <0.8.0;
pragma experimental ABIEncoderV2;

import "./MarketLib.sol";
import "./MyERC721.sol";


// Step one:  I declare the already-deployed "CryptoPunksMarket" contract 
contract CryptoPunksMarket {
    mapping (uint => address) public punkIndexToAddress;
}

My understanding is that you don't have to declare the ENTIRE contract you're trying to interface with, but only the specific methods you're interested in - which is why I only declare the punkIndexToAddress mapping.

Next is my contract:

contract MyMarketplace is MyERC721 {

   using MarketLib for MarketLib.PunkCell;

   // Here's the reference to the "CryptoPunksMarket" using it's deployed Ethereum address:
   CryptoPunksMarket punksContract = CryptoPunksMarket(0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB);

   address public punk9999OwnerAddress;


   constructor() MyERC721() public { 

      // Trying to access the "punkIndexToAddress" public mapping from that contract:
      punk9999OwnerAddress = punksContract.punkIndexToAddress(9999);

      // etc.
   }
}

Here's what happens when I try to deploy this using localhost with Truffle:

Error:  *** Deployment Failed ***

"MyMarketplace" hit a require or revert statement somewhere in its constructor. Try:
   * Verifying that your constructor params satisfy all require conditions.
   * Adding reason strings to your require statements.

Since I have no idea why this is happening, I tried moving the code out of the Constructor into its own separate function, just to see if that would make a difference - or at least give me a different wording for the Error when it crashes.

So I did this:

function getOwnerOfPunkNumber() public returns (address ownerOfPunk) {
    return punksContract.punkIndexToAddress(9999);
}

Using truffle, I tried calling that function - here's the result of that:

truffle(development)> myContract.getOwnerOfPunkNumber()
Uncaught Error: Returned error: VM Exception while processing transaction: revert
    at evalmachine.<anonymous>:0:12
    at sigintHandlersWrap (vm.js:272:15)
    at Script.runInContext (vm.js:139:14)
    at runScript (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:251:1)
    at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:266:1)
    at bound (domain.js:430:14)
    at REPLServer.runBound [as eval] (domain.js:443:12)
    at REPLServer.onLine (repl.js:817:10)
    at REPLServer.emit (events.js:315:20)
    at REPLServer.EventEmitter.emit (domain.js:486:12)
    at REPLServer.Interface._onLine (readline.js:337:10)
    at REPLServer.Interface._line (readline.js:666:8)
    at REPLServer.Interface._ttyWrite (readline.js:1010:14)
    at REPLServer.self._ttyWrite (repl.js:907:9)
    at ReadStream.onkeypress (readline.js:213:10)
    at ReadStream.emit (events.js:315:20)
    at ReadStream.EventEmitter.emit (domain.js:486:12)
    at emitKeys (internal/readline/utils.js:345:14)
    at emitKeys.next (<anonymous>)
    at ReadStream.onData (readline.js:1144:36)
    at ReadStream.emit (events.js:315:20)
    at ReadStream.EventEmitter.emit (domain.js:486:12)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:284:9)
    at ReadStream.Readable.push (_stream_readable.js:223:10)

etc.

So what am I doing wrong here? Does this have to do with different Solidity Compiler versions? Or the fact that my contract uses pragma experimental ABIEncoderV2?

I feel like that first error I got - when the code was in the Constructor - is really telling, but I have no idea what it might be referring to, since I have no require or revert statements in my constructor:

"MyMarketplace" hit a require or revert statement somewhere in its constructor. Try:
   * Verifying that your constructor params satisfy all require conditions.
   * Adding reason strings to your require statements.

Any ideas what might be happening here?

1
  • I don't why it fails, perhaps is due to pragma experimental since CryptoPunk uses solc 0.4.18. You can try declaring it as a getter function punkIndexToAddress(uint256) external view returns (address). – Ismael May 7 at 3:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.