Cyfrin / foundry-nft-cu

21 stars 22 forks source link

Error: script failed: unknown selector `0xdb4235f6` for VmCalls while minting #31

Closed AndroKasrashvili closed 3 months ago

AndroKasrashvili commented 4 months ago

here are my Interactions.s.sol at this point:

//SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

import {Script} from "forge-std/Script.sol";

import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol";
import {BasicNft} from "../src/BasicNft.sol";

contract MintBasicNft is Script {
    string public constant GSD =
        "ipfs://QmZqxBsEWgxGaPP8Q3cxxuYarivVfietTUzJ9cNfAAZqch";

    function run() external {
        address mostRecentlyDeployed = DevOpsTools.get_most_recent_deployment(
            "BasicNft",
            block.chainid
        );
        mintNftOnContract(mostRecentlyDeployed);
    }

    function mintNftOnContract(address contractAddress) public {
        vm.startBroadcast();
        BasicNft(contractAddress).mintNft(GSD);
        vm.stopBroadcast();
    }
}

this is my BasicNft.sol:

//SPDX-Licence-Identifier: MIT

pragma solidity ^0.8.18;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract BasicNft is ERC721 {
    uint256 private s_tokenCounter;
    mapping(uint256 => string) private s_tokenIdToURI;

    constructor() ERC721("Dogie", "DOG") {
        s_tokenCounter = 0;
    }

    function mintNft(string memory tokenUri) public {
        s_tokenIdToURI[s_tokenCounter] = tokenUri;
        _safeMint(msg.sender, s_tokenCounter);
        s_tokenCounter++;
    }

    function tokenURI(
        uint256 tokenId
    ) public view override returns (string memory) {}
}

foundry.toml

[profile.default]
src = "src"
out = "out"
libs = ["lib"]
fs_permissions = [
    { access = "read", path = "./broadcast" },
    { access = "read", path = "./reports" },
]
remappings = ['@openzeppelin=lib/openzeppelin-contracts']
ffi = true
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

Makefile:

-include .env

.PHONY: all test clean deploy fund help install snapshot format anvil 

DEFAULT_ANVIL_KEY := 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

help:
    @echo "Usage:"
    @echo "  make deploy [ARGS=...]\n    example: make deploy ARGS=\"--network sepolia\""
    @echo ""
    @echo "  make fund [ARGS=...]\n    example: make deploy ARGS=\"--network sepolia\""

all: clean remove install update build

# Clean the repo
clean  :; forge clean

# Remove modules
remove :; rm -rf .gitmodules && rm -rf .git/modules/* && rm -rf lib && touch .gitmodules && git add . && git commit -m "modules"

install :; forge install Cyfrin/foundry-devops@0.1.0 --no-commit && forge install foundry-rs/forge-std@v1.5.3 --no-commit && forge install openzeppelin/openzeppelin-contracts@v4.8.3 --no-commit

# Update Dependencies
update:; forge update

build:; forge build

test :; forge test 

snapshot :; forge snapshot

format :; forge fmt

anvil :; anvil -m 'test test test test test test test test test test test junk' --steps-tracing --block-time 1

NETWORK_ARGS := --rpc-url http://localhost:8545 --private-key $(DEFAULT_ANVIL_KEY) --broadcast

ifeq ($(findstring --network sepolia,$(ARGS)),--network sepolia)
    NETWORK_ARGS := --rpc-url $(SEPOLIA_RPC_URL) --private-key $(PRIVATE_KEY) --broadcast --verify --etherscan-api-key $(ETHERSCAN_API_KEY) -vvvv
endif

deploy:
    @forge script script/DeployBasicNft.s.sol:DeployBasicNft $(NETWORK_ARGS)

mint:
    @forge script script/Interactions.s.sol:MintBasicNft ${NETWORK_ARGS}

# deployMood:
#   @forge script script/DeployMoodNft.s.sol:DeployMoodNft $(NETWORK_ARGS)

# mintMoodNft:
#   @forge script script/Interactions.s.sol:MintMoodNft $(NETWORK_ARGS)

# flipMoodNft:
#   @forge script script/Interactions.s.sol:FlipMoodNft $(NETWORK_ARGS)

error in terminal:

make mint ARGS="--network sepolia"
[⠒] Compiling...
[⠔] Compiling 1 files with 0.8.24
[⠒] Solc 0.8.24 finished in 1.39s
Compiler run successful!
Traces:
  [941479] → new MintBasicNft@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
    └─ ← 4592 bytes of code

  [311908] MintBasicNft::run()
    ├─ [0] VM::readDir("./broadcast", 3) [staticcall]
    │   └─ ← [("", "/Users/fun/Code/researchWEB3/foundry-f23/NFT/broadcast/DeployBasicNft.s.sol", 1, true, false), ("", "/Users/fun/Code/researchWEB3/foundry-f23/NFT/broadcast/DeployBasicNft.s.sol/11155111", 2, true, false), ("", "/Users/fun/Code/researchWEB3/foundry-f23/NFT/broadcast/DeployBasicNft.s.sol/11155111/run-1715598058.json", 3, false, false), ("", "/Users/fun/Code/researchWEB3/foundry-f23/NFT/broadcast/DeployBasicNft.s.sol/11155111/run-1715598078.json", 3, false, false), ("", "/Users/fun/Code/researchWEB3/foundry-f23/NFT/broadcast/DeployBasicNft.s.sol/11155111/run-1715598101.json", 3, false, false), ("", "/Users/fun/Code/researchWEB3/foundry-f23/NFT/broadcast/DeployBasicNft.s.sol/11155111/run-1715676595.json", 3, false, false), ("", "/Users/fun/Code/researchWEB3/foundry-f23/NFT/broadcast/DeployBasicNft.s.sol/11155111/run-1715676602.json", 3, false, false), ("", "/Users/fun/Code/researchWEB3/foundry-f23/NFT/broadcast/DeployBasicNft.s.sol/11155111/run-1715676656.json", 3, false, false), ("", "/Users/fun/Code/researchWEB3/foundry-f23/NFT/broadcast/DeployBasicNft.s.sol/11155111/run-latest.json", 3, false, false)]
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← "11155111"
    ├─ [0] VM::toString(11155111 [1.115e7]) [staticcall]
    │   └─ ← "11155111"
    ├─ [0] VM::readFile("/Users/fun/Code/researchWEB3/foundry-f23/NFT/broadcast/DeployBasicNft.s.sol/11155111/run-1715598058.json") [staticcall]
    │   └─ ← <file>
    ├─ [0] VM::parseJsonUint("<stringified JSON>", ".timestamp") [staticcall]
    │   └─ ← 1715598058 [1.715e9]
    ├─ [0] VM::toString(0) [staticcall]
    │   └─ ← "0"
    ├─ [0] VM::keyExistsJson("{\n  \"transactions\": [\n    {\n      \"hash\": \"0xdcc94544283d17c4fbaaaee44a42b215211c3b70525db70cd9ec78dcf60da55f\",\n      \"transactionType\": \"CREATE\",\n      \"contractName\": \"BasicNft\",\n      \"contractAddress\": \"0x675b8829Dd7D36d186982C812A5e9EA7C2D97De6\",\n      \"function\": null,\n      \"arguments\": null,\n      \"transaction\": {\n        \"type\": \"0x02\",\n        \"from\": \"0xe19045a825419b434928cd50f7d6c448a9d7bd56\",\n        \"gas\": \"0x1300ff\",\n        \"value\": \"0x0\",\n        \"data\": \"0x60806040523480156200001157600080fd5b5060405180604001604052806005815260200164446f67696560d81b81525060405180604001604052806003815260200162444f4760e81b81525081600090816200005d919062000121565b5060016200006c828262000121565b5050600060065550620001ed565b634e487b7160e01b600052604160045260246000fd5b600181811c90821680620000a557607f821691505b602082108103620000c657634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200011c576000816000526020600020601f850160051c81016020861015620000f75750805b601f850160051c820191505b81811015620001185782815560010162000103565b5050505b505050565b81516001600160401b038111156200013d576200013d6200007a565b62000155816200014e845462000090565b84620000cc565b602080601f8311600181146200018d5760008415620001745750858301515b600019600386901b1c1916600185901b17855562000118565b600085815260208120601f198616915b82811015620001be578886015182559484019460019091019084016200019d565b5085821015620001dd5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b610f6280620001fd6000396000f3fe608060405234801561001057600080fd5b50600436106100ea5760003560e01c806370a082311161008c578063b88d4fde11610066578063b88d4fde146101e1578063c87b56dd146101f4578063da86f4a914610208578063e985e9c51461021b57600080fd5b806370a08231146101a557806395d89b41146101c6578063a22cb465146101ce57600080fd5b8063095ea7b3116100c8578063095ea7b31461015757806323b872dd1461016c57806342842e0e1461017f5780636352211e1461019257600080fd5b806301ffc9a7146100ef57806306fdde0314610117578063081812fc1461012c575b600080fd5b6101026100fd366004610a76565b61022e565b60405190151581526020015b60405180910390f35b61011f610280565b60405161010e9190610ae0565b61013f61013a366004610af3565b610312565b6040516001600160a01b03909116815260200161010e565b61016a610165366004610b28565b61033b565b005b61016a61017a366004610b52565b61034a565b61016a61018d366004610b52565b6103da565b61013f6101a0366004610af3565b6103fa565b6101b86101b3366004610b8e565b610405565b60405190815260200161010e565b61011f61044d565b61016a6101dc366004610ba9565b61045c565b61016a6101ef366004610c71565b610467565b61011f610202366004610af3565b50606090565b61016a610216366004610ced565b61047f565b610102610229366004610d36565b6104bf565b60006001600160e01b031982166380ac58cd60e01b148061025f57506001600160e01b03198216635b5e139f60e01b145b8061027a57506301ffc9a760e01b6001600160e01b03198316145b92915050565b60606000805461028f90610d69565b80601f01602080910402602001604051908101604052809291908181526020018280546102bb90610d69565b80156103085780601f106102dd57610100808354040283529160200191610308565b820191906000526020600020905b8154815290600101906020018083116102eb57829003601f168201915b5050505050905090565b600061031d826104ed565b506000828152600460205260409020546001600160a01b031661027a565b610346828233610526565b5050565b6001600160a01b03821661037957604051633250574960e11b8152600060048201526024015b60405180910390fd5b6000610386838333610533565b9050836001600160a01b0316816001600160a01b0316146103d4576040516364283d7b60e01b81526001600160a01b0380861660048301526024820184905282166044820152606401610370565b50505050565b6103f583838360405180602001604052806000815250610467565b505050565b600061027a826104ed565b60006001600160a01b038216610431576040516322718ad960e21b815260006004820152602401610370565b506001600160a01b031660009081526003602052604090205490565b60606001805461028f90610d69565b61034633838361062c565b61047284848461034a565b6103d433858585856106cb565b600654600090815260076020526040902061049a8282610deb565b506104a7336006546107f6565b600680549060006104b783610eab565b919050555050565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b6000818152600260205260408120546001600160a01b03168061027a57604051637e27328960e01b815260048101849052602401610370565b6103f58383836001610810565b6000828152600260205260408120546001600160a01b039081169083161561056057610560818486610916565b6001600160a01b0381161561059e5761057d600085600080610810565b6001600160a01b038116600090815260036020526040902080546000190190555b6001600160a01b038516156105cd576001600160a01b0385166000908152600360205260409020805460010190555b60008481526002602052604080822080546001600160a01b0319166001600160a01b0389811691821790925591518793918516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4949350505050565b6001600160a01b03821661065e57604051630b61174360e31b81526001600160a01b0383166004820152602401610370565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6001600160a01b0383163b156107ef57604051630a85bd0160e11b81526001600160a01b0384169063150b7a029061070d908890889087908790600401610ed2565b6020604051808303816000875af1925050508015610748575060408051601f3d908101601f1916820190925261074591810190610f0f565b60015b6107b1573d808015610776576040519150601f19603f3d011682016040523d82523d6000602084013e61077b565b606091505b5080516000036107a957604051633250574960e11b81526001600160a01b0385166004820152602401610370565b805181602001fd5b6001600160e01b03198116630a85bd0160e11b146107ed57604051633250574960e11b81526001600160a01b0385166004820152602401610370565b505b5050505050565b61034682826040518060200160405280600081525061097a565b808061082457506001600160a01b03821615155b156108e6576000610834846104ed565b90506001600160a01b038316158015906108605750826001600160a01b0316816001600160a01b031614155b8015610873575061087181846104bf565b155b1561089c5760405163a9fbf51f60e01b81526001600160a01b0384166004820152602401610370565b81156108e45783856001600160a01b0316826001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45b505b5050600090815260046020526040902080546001600160a01b0319166001600160a01b0392909216919091179055565b610921838383610992565b6103f5576001600160a01b03831661094f57604051637e27328960e01b815260048101829052602401610370565b60405163177e802f60e01b81526001600160a01b038316600482015260248101829052604401610370565b61098483836109f8565b6103f53360008585856106cb565b60006001600160a01b038316158015906109f05750826001600160a01b0316846001600160a01b031614806109cc57506109cc84846104bf565b806109f057506000828152600460205260409020546001600160a01b038481169116145b949350505050565b6001600160a01b038216610a2257604051633250574960e11b815260006004820152602401610370565b6000610a3083836000610533565b90506001600160a01b038116156103f5576040516339e3563760e11b815260006004820152602401610370565b6001600160e01b031981168114610a7357600080fd5b50565b600060208284031215610a8857600080fd5b8135610a9381610a5d565b9392505050565b6000815180845260005b81811015610ac057602081850181015186830182015201610aa4565b506000602082860101526020601f19601f83011685010191505092915050565b602081526000610a936020830184610a9a565b600060208284031215610b0557600080fd5b5035919050565b80356001600160a01b0381168114610b2357600080fd5b919050565b60008060408385031215610b3b57600080fd5b610b4483610b0c565b946020939093013593505050565b600080600060608486031215610b6757600080fd5b610b7084610b0c565b9250610b7e60208501610b0c565b9150604084013590509250925092565b600060208284031215610ba057600080fd5b610a9382610b0c565b60008060408385031215610bbc57600080fd5b610bc583610b0c565b915060208301358015158114610bda57600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b600067ffffffffffffffff80841115610c1657610c16610be5565b604051601f8501601f19908116603f01168101908282118183101715610c3e57610c3e610be5565b81604052809350858152868686011115610c5757600080fd5b858560208301376000602087830101525050509392505050565b60008060008060808587031215610c8757600080fd5b610c9085610b0c565b9350610c9e60208601610b0c565b925060408501359150606085013567ffffffffffffffff811115610cc157600080fd5b8501601f81018713610cd257600080fd5b610ce187823560208401610bfb565b91505092959194509250565b600060208284031215610cff57600080fd5b813567ffffffffffffffff811115610d1657600080fd5b8201601f81018413610d2757600080fd5b6109f084823560208401610bfb565b60008060408385031215610d4957600080fd5b610d5283610b0c565b9150610d6060208401610b0c565b90509250929050565b600181811c90821680610d7d57607f821691505b602082108103610d9d57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156103f5576000816000526020600020601f850160051c81016020861015610dcc5750805b601f850160051c820191505b818110156107ed57828155600101610dd8565b815167ffffffffffffffff811115610e0557610e05610be5565b610e1981610e138454610d69565b84610da3565b602080601f831160018114610e4e5760008415610e365750858301515b600019600386901b1c1916600185901b1785556107ed565b600085815260208120601f198616915b82811015610e7d57888601518255948401946001909101908401610e5e565b5085821015610e9b5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b600060018201610ecb57634e487b7160e01b600052601160045260246000fd5b5060010190565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090610f0590830184610a9a565b9695505050505050565b600060208284031215610f2157600080fd5b8151610a9381610a5d56fea2646970667358221220a33317e42e694260aa0ae4b87af240c7aa208b1f8ee6ebde9fa68a3e818298e264736f6c63430008180033\",\n        \"nonce\": \"0x7\",\n        \"accessList\": []\n      },\n      \"additionalContracts\": [],\n      \"isFixedGasLimit\": false\n    }\n  ],\n  \"receipts\": [],\n  \"libraries\": [],\n  \"pending\": [\n    \"0xdcc94544283d17c4fbaaaee44a42b215211c3b70525db70cd9ec78dcf60da55f\"\n  ],\n  \"returns\": {\n    \"0\": {\n      \"internal_type\": \"contract BasicNft\",\n      \"value\": \"0x675b8829Dd7D36d186982C812A5e9EA7C2D97De6\"\n    }\n  },\n  \"timestamp\": 1715598058,\n  \"chain\": 11155111,\n  \"multi\": false,\n  \"commit\": \"f0bda1b\"\n}", "$.transactions[0]") [staticcall]
    │   └─ ← unknown selector `0xdb4235f6` for VmCalls
    └─ ← unknown selector `0xdb4235f6` for VmCalls

Error: 
script failed: unknown selector `0xdb4235f6` for VmCalls
make: *** [mint] Error 1

I am using files in IPFS uploaded by me, have tried URI provided in this repo, same error. any ideas?

Thanks!

cromewar commented 4 months ago

Hello @AndroKasrashvili

It seems your problem is related to the VMCalls for using an undefined or unsupported function. This tends to happen mostly because of a mismatch in the version with the Solidity compiler, foundry, or both.

I reviewed your code, and it seems to be all fine, so before we delve deep into more possible solutions, try this:

  1. Be sure your foundry installation is updated with foundryup.
  2. Be sure to use the same solidity version on the contracts 0.8.19, you use .18 on one of them.
  3. on the toml file use 0.8.19.
  4. Rebuild the project: forge clean and forge build.
  5. change the ARGS on the makefile to use the specific solidity version:
ARGS="--network sepolia --compiler-version 0.8.19"

Did any of these solutions help you? If not, let us know, and I will try to reproduce this error on my end.

jestanoff commented 3 months ago

Update your foundry to the latest version as they migrated to native assertions and your current foundry version does not include them.

foundryup
AndroKasrashvili commented 3 months ago

@cromewar matching solidity version in all contracts and foundryup command solved the problem.

Thank You!