Skip to content

Files

Latest commit

40e8872 · Feb 3, 2020

History

History
This branch is 1 commit ahead of, 11293 commits behind NomicFoundation/hardhat:main.

docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jan 24, 2020
Jan 22, 2020
Jan 24, 2020
Dec 18, 2019
Oct 2, 2019
Feb 3, 2020
Oct 2, 2019
Oct 2, 2019
Oct 2, 2019
Oct 2, 2019
Jan 24, 2020
Oct 2, 2019
Oct 2, 2019
Oct 2, 2019
Oct 2, 2019
Oct 2, 2019
Apr 12, 2019
Oct 2, 2019
Oct 2, 2019
Oct 2, 2019
home heroImage actionText search footer
true
./mascots.svg
Get Started
false
Copyright © 2018-2019 Nomic Labs LLC

1. Write your contract

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

pragma solidity ^0.5.1;
    
contract DeathStar is ERC721 {

  address private owner;

  constructor (address owner) public {
    owner = owner;
  }

  function shoot(string memory planet) public {
    require(msg.sender == owner);
    // TODO: BAM
  }
}

2. Choose your plugins & setup

// For unit tests
usePlugin("@nomiclabs/buidler-truffle5");
usePlugin("@nomiclabs/buidler-ganache");
usePlugin("buidler-gas-reporter");

// Linting
usePlugin("@nomiclabs/buidler-solhint");

// For scripts
usePlugin("@nomiclabs/buidler-ethers");

// Faster compilation
usePlugin("@nomiclabs/buidler-docker-solc");

module.exports = {
  buidlerevm: {
    throwOnTransactionFailures: true
  }
};

3. Write your tests

contract('ERC721', function () {
  describe('safeTransferFrom to a contract that does not implement the required function', function () {
    it('reverts', async function () {

      const invalidReceiver = this.token;

      await this.token.safeTransferFrom(
        owner,
        invalidReceiver.address,
        tokenId,
        { from: owner }
      )        
    });
  });
});

4. Debug your code with Buidler EVM

$ npx buidler test

Contract: DeathStar
  safeTransferFrom to a contract that does not implement the required function:

Error: Transaction reverted: function selector was not recognized and there's no fallback function
  at DeathStar.<unrecognized-selector> (contracts/DeathStar.sol:9)
  at DeathStar._checkOnERC721Received (contracts/token/ERC721/ERC721.sol:334)
  at DeathStar._safeTransferFrom (contracts/token/ERC721/ERC721.sol:196)
  at DeathStar.safeTransferFrom (contracts/token/ERC721/ERC721.sol:179)
  at DeathStar.safeTransferFrom (contracts/token/ERC721/ERC721.sol:162)
  at TruffleContract.safeTransferFrom (node_modules/@nomiclabs/truffle-contract/lib/execute.js:157:24)
  at Context.<anonymous> (test/DeathStar-test.js:321:26)