Cyfrin / foundry-nft-cu

22 stars 25 forks source link

Encountring error with "make mint " #36

Closed ShaneOxM closed 4 months ago

ShaneOxM commented 4 months ago

When attempting to run make mint ARGS=" --network sepolia I receive the below error mentioning a revert due to "No deployment artifacts" being found for the specified chain. The deploy successfully verified on etherscan, but I keep having this issue with the "mint".

Full Error Message:


$ make mint ARGS=" --network sepolia"
[⠒] Compiling...
No files changed, compilation skipped
Traces:
  [949286] → new MintBasicNft@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
    └─ ← [Return] 4631 bytes of code

  [278816] MintBasicNft::run()
    ├─ [0] VM::readDir("./broadcast", 3) [staticcall]
    │   └─ ← [Return] [("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol", 1, true, false), ("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol\\11155111", 2, true, false), ("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol\\11155111\\run-1719249854.json", 3, false, false), ("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol\\11155111\\run-1719254863.json", 3, false, false), ("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol\\11155111\\run-1719255297.json", 3, false, false), ("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol\\11155111\\run-latest.json", 3, false, false)]
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    └─ ← [Revert] revert: No deployment artifacts were found for specified chain

Error:
script failed: revert: No deployment artifacts were found for specified chain
make: *** [Makefile:46: mint] Error 1
ShaneOxM commented 4 months ago

Seems that error is reverting from the DevOpsTools.sol file. Have attached incase this is useful in further assessing the reason for the revert


// SPDX-License-Identifier: MIT

pragma solidity >=0.8.13 <0.9.0;

import {Vm} from "lib/forge-std/src/Vm.sol";
import {stdJson} from "lib/forge-std/src/StdJson.sol";
import {StdCheatsSafe} from "lib/forge-std/src/StdCheats.sol";
import {console} from "lib/forge-std/src/console.sol";
import {StringUtils} from "./StringUtils.sol";

library DevOpsTools {
    using stdJson for string;
    using StringUtils for string;

    Vm public constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));

    string public constant RELATIVE_BROADCAST_PATH = "./broadcast";

    function get_most_recent_deployment(string memory contractName, uint256 chainId) internal view returns (address) {
        return get_most_recent_deployment(contractName, chainId, RELATIVE_BROADCAST_PATH);
    }

    function get_most_recent_deployment(
        string memory contractName,
        uint256 chainId,
        string memory relativeBroadcastPath
    ) internal view returns (address) {
        address latestAddress = address(0);
        uint256 lastTimestamp;

        bool runProcessed;
        Vm.DirEntry[] memory entries = vm.readDir(relativeBroadcastPath, 3);
        for (uint256 i = 0; i < entries.length; i++) {
            Vm.DirEntry memory entry = entries[i];
            if (
                entry.path.contains(string.concat("/", vm.toString(chainId), "/")) && entry.path.contains(".json")
                    && !entry.path.contains("dry-run")
            ) {
                runProcessed = true;
                string memory json = vm.readFile(entry.path);

                uint256 timestamp = vm.parseJsonUint(json, ".timestamp");

                if (timestamp > lastTimestamp) {
                    latestAddress = processRun(json, contractName, latestAddress);

                    // If we have found some deployed contract, update the timestamp
                    // Otherwise, the earliest deployment may have been before `lastTimestamp` and we should not update
                    if (latestAddress != address(0)) {
                        lastTimestamp = timestamp;
                    }
                }
            }
        }

        if (!runProcessed) {
            revert("No deployment artifacts were found for specified chain");
        }

        if (latestAddress != address(0)) {
            return latestAddress;
        } else {
            revert("No contract deployed");
        }
    }

    function processRun(string memory json, string memory contractName, address latestAddress)
        internal
        view
        returns (address)
    {
        for (uint256 i = 0; vm.keyExistsJson(json, string.concat("$.transactions[", vm.toString(i), "]")); i++) {
            string memory contractNamePath = string.concat("$.transactions[", vm.toString(i), "].contractName");
            if (vm.keyExistsJson(json, contractNamePath)) {
                string memory deployedContractName = json.readString(contractNamePath);
                if (deployedContractName.isEqualTo(contractName)) {
                    latestAddress =
                        json.readAddress(string.concat("$.transactions[", vm.toString(i), "].contractAddress"));
                }
            }
        }

        return latestAddress;
    }
}
PatrickAlphaC commented 4 months ago

Thanks!

Could you check the following:

  1. You have this in your foundry.toml

    fs_permissions = [
    { access = "read", path = "./images/" },
    { access = "read", path = "./broadcast" },
    ]
  2. Could you try running a raw forge function?

forge script script/Interactions.s.sol:MintBasicNft --account <YOUR_ACCOUNT> --rpc-url <RPC_URL> --broadcast
  1. Did you deploy an NFT already? It should be tracked in your broadcast folder. You can look for it in there.
ShaneOxM commented 4 months ago

Thanks for the response.

  1. Yes, here is my current foundry.toml

[profile.default] src = "src" out = "out" libs = ["lib"] ffi = true fs_permissions = [ { access = "read", path = "./images/" }, { access = "read", path = "./broadcast" }, ]

remappings = ['@openzeppelin/contracts=lib/openzeppelin-contracts/contracts']

[etherscan] mainnet = { key = "${ETHERSCAN_API_KEY}" } sepolia = { key = "${ETHERSCAN_API_KEY}" }

[rpc_endpoints] sepolia = "${SEPOLIA_RPC_URL}"

See more config options https://github.com/foundry-rs/foundry/tree/master/config



2.  I will give this a try. In this case would the placeholder 'YOUR_ACCOUNT' be filled with my private key or etherscan api? 

3.  The NFT deploys to etherscan no problem at all, it appears to only be when I attempt to mint that I am faced with the <script failed: revert: No deployment artifacts were found for specified chain
make: *** [Makefile:46: mint] Error 1>  , which appears to be pointing to my Makefile in line 46.

Line 46 in Makefile:

![image](https://github.com/Cyfrin/foundry-nft-cu/assets/169729951/d823f93e-51a6-4dc6-9740-0018dbbddc11)

Hope this helps. Much appreciate the guidance here
ShaneOxM commented 4 months ago

Ran it with my private key sourced from .env and it reverted with the same error message:


$ forge script script/Interactions.s.sol:MintBasicNft --private-key $PRIVATE_KEY --rpc-url $SEPOLIA_RPC_URL --broadcast
[⠆] Compiling...
No files changed, compilation skipped
Traces:
  [949286] → new MintBasicNft@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
    └─ ← [Return] 4631 bytes of code

  [328975] MintBasicNft::run()
    ├─ [0] VM::readDir("./broadcast", 3) [staticcall]
    │   └─ ← [Return] [("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol", 1, true, false), ("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol\\11155111", 2, true, false), ("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol\\11155111\\run-1719249854.json", 3, false, false), ("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol\\11155111\\run-1719254863.json", 3, false, false), ("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol\\11155111\\run-1719255297.json", 3, false, false), ("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol\\11155111\\run-1719272432.json", 3, false, false), ("", "C:/Users/shane/foundry-f23/foundry-nft-f23/broadcast\\DeployBasicNft.s.sol\\11155111\\run-latest.json", 3, false, false)]
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← [Return] "11155111"
    └─ ← [Revert] revert: No deployment artifacts were found for specified chain

Error: 
script failed: revert: No deployment artifacts were found for specified chain
PatrickAlphaC commented 4 months ago

Can you share what your broadcast folder looks like? It should look like this, but with the sepolia chain id and correct script name.

The way the foundry-devops tool works, is it reads your deployments from that folder to get the correct address. You could also manually get the address and update your script. But if there is a bug in foundry-devops we should fix that. So, wondering what your broadcast folder looks like.

Screenshot 2024-06-24 at 10 12 59 PM

And in run-latest.json, you should see CREATE and a value for contractAddress:

Screenshot 2024-06-24 at 10 14 33 PM
ShaneOxM commented 4 months ago

Makes sense, thanks for the insight. My broadcast appears to the same as yours but with the Sepolia Chainid: 11155111

image

This is what I see in run-latest.json

image

juanc004 commented 3 months ago

Hey @ShaneOxM @PatrickAlphaC

I encountered an issue while running the command make mint ARGS="--network sepolia", where the script failed with the error: "revert: No contract deployed." I referenced all the messages to ensure everything was set up properly but am still experiencing this issue.

Could you clarify what the solution was for this issue? Any guidance or insights would be greatly appreciated.

Thank you for your help!

PatrickAlphaC commented 3 months ago

Yes! If you didn't deploy a smart contract, you can't call the mint function on it!