在一个合约里部署2个contract会有问题吗?

比如下面这一段代码,里面有2个合约,并且2个合约之间没有关系, 我把这段代码用 Remix可以成功部署, 那我在使用的时候, 会冲突吗

因为这2个contract都有 get set方法 ,所以我担心未来可能出现什么bug

有前辈可以指点一二吗, 谢谢

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract Mapping {
    // Mapping from address to uint
    mapping(address => uint) public myMap;

    function get(address _addr) public view returns (uint) {
        // Mapping always returns a value.
        // If the value was never set, it will return the default value.
        return myMap[_addr];
    }

    function set(address _addr, uint _i) public {
        // Update the value at this address
        myMap[_addr] = _i;
    }

    function remove(address _addr) public {
        // Reset the value to the default value.
        delete myMap[_addr];
    }
}

contract NestedMapping {
    // Nested mapping (mapping from address to another mapping)
    mapping(address => mapping(uint => bool)) public nested;

    function get(address _addr1, uint _i) public view returns (bool) {
        // You can get values from a nested mapping
        // even when it is not initialized
        return nested[_addr1][_i];
    }

    function set(
        address _addr1,
        uint _i,
        bool _boo
    ) public {
        nested[_addr1][_i] = _boo;
    }

    function remove(address _addr1, uint _i) public {
        delete nested[_addr1][_i];
    }
}
请先 登录 后评论

最佳答案 2022-10-26 10:40

remix在部署的时候这里是可以选哪个contract来部署的 image.png 你没看到应该是默认部署了其中某一个

请先 登录 后评论

其它 2 个回答

Tiny熊 - 布道者
  擅长:智能合约,以太坊
请先 登录 后评论
gasshadow
请先 登录 后评论
  • 3 关注
  • 0 收藏,1032 浏览
  • 提出于 2022-10-19 13:28

相似问题