0

我正在尝试使用另一个智能合约部署合约“SimpleStorage.sol”,但每次尝试使用我创建的功能时都会出错。

我认为我的代码没有任何问题,但我可能是错的。Imgur 截图链接:https ://imgur.com/a/vJYbmKi

这是 SimpleStorage.sol 合约:

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;         //solidity versions 0.6.0 -> 0.9.0

contract SimpleStorage {

    struct People{
        uint256 favNum;
        string Name;
    }

    People public person = People({favNum : 2, Name : "Patrick"});
    
    People[] public peoplearr; //dynamic array

    mapping(string => uint256) public nameTofavNum; //string becca is mapping the uint256 given by user

    //initialized to 0
    uint256 favNum;
    
    function store(uint256 _favNum) public{ 
        favNum = _favNum;
    }

    function retrieve() public view returns(uint256){
        return favNum;
    }

    function addPerson(string memory _Name, uint256 _favNum) public{
        peoplearr.push(People({favNum : _favNum, Name : _Name})); //added person to peoplearr
        nameTofavNum[_Name] = _favNum;                            //adds tp mapping
    }  
}

这是应该部署另一个合同的合同:


// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

import "./SimpleStorage.sol";

contract ArbFactory {

    SimpleStorage[] public SimpleStorageArr;

    function CreateNewContract() public{

        //creates new contract in external scope, new variable in local scope
        SimpleStorage newContract = new SimpleStorage(); 
        //pushes new contract onto the array
        SimpleStorageArr.push(newContract);

    }

    function functionCallOne(uint256 _SimpleStorageIndex, uint256 _SimpleStorageNumber) public{
        //ABI and address required to interact with contract functions 

        SimpleStorage manCon = SimpleStorage(address(SimpleStorageArr[_SimpleStorageIndex]));
        //manCon is the variable name for the contract to manipulate. 
        //Now it is possible to call any function of the same type(public) within the contract.

        manCon.store(_SimpleStorageNumber);

    }

    function functionCallTwo(uint256 _SimpleStorageIndex) public view returns(uint256){
        SimpleStorage manCon = SimpleStorage(address(SimpleStorageArr[_SimpleStorageIndex]));
        return manCon.retrieve();
    }

}

错误信息是imgur中的最后一张图片,感谢任何可以提供帮助的人。

4

0 回答 0