简体   繁体   English

将 Web3.Py 中的元组或地址列表传递给部署合约

[英]Passing Tuple or List of addresses in Web3.Py to Deploy contract

So I'm trying to deploy a smart contract which requires as part of its constructor function a list of addresses.所以我试图部署一个智能合约,它需要一个地址列表作为其构造函数的一部分。 I am using the deployment script and passing it a tuple of hexadecimal strings at no avail.我正在使用部署脚本并将十六进制字符串元组传递给它,但无济于事。 I've tried lists of strings, tuples of bytes, etc. If anyone can tell me what data type I need to pass into this smart contract for a list of addresses that would be amazing.我已经尝试过字符串列表、字节元组等。如果有人能告诉我我需要将什么数据类型传递给这个智能合约以获得地址列表,那就太棒了。 See here my deployment script:在这里查看我的部署脚本:

from brownie import accounts, config, Turtles, network
from web3 import Web3 as web3


def deploy_turtles():
    # Grabbing an account from 0th index of Brownie's ganache default wallets
    account = get_account()
    address1 = web3.toChecksumAddress(0x4A40E425A8D1EE6279F860D8FD5DB3D3661558D6)
    address2 = web3.toChecksumAddress(0xA9873C4C5FBD0196D0FBA2E50A3EEE216C4D6780)

    addresses = (address1, address2)
    turtle_deployed = Turtles.deploy(
        "Turtles",
        "Turtle",
        "ipfs://bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354/",
        [100, 10, 20000, 20, 10, 1655480363, 1655473254, 100],
        "ea58dfa481a0c08b4af0417e3f62244215a1ab1eae0a100da48407be5cdd94b7",
        addresses,
        [10, 15],
        addresses,
        700,
        {"from": account},
        publish_source=True,
    )

And below you can see the smart contract I am trying to deploy along with its relevant constructor:在下面,您可以看到我正在尝试部署的智能合约及其相关构造函数:

// SPDX-License-Identifier: AGPL-3.0

pragma solidity ^0.8.9;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/finance/PaymentSplitter.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "./ERC721AWithRoyalties.sol";

contract Turtles is Ownable, ERC721AWithRoyalties, Pausable, PaymentSplitter {
    string public _baseTokenURI;

    bytes32 public _merkleRoot;

    uint256 public _price;
    uint256 public _presalePrice;
    uint256 public _maxSupply;
    uint256 public _maxPerAddress;
    uint256 public _presaleMaxPerAddress;
    uint256 public _publicSaleTime;
    uint256 public _preSaleTime;
    uint256 public _maxTxPerAddress;
    mapping(address => uint256) private _purchases;

    event EarlyPurchase(
        address indexed addr,
        uint256 indexed atPrice,
        uint256 indexed count
    );
    event Purchase(
        address indexed addr,
        uint256 indexed atPrice,
        uint256 indexed count
    );

    constructor(
        string memory name,
        string memory symbol,
        string memory baseTokenURI, // baseTokenURI - 0
        uint256[] memory numericValues, // price - 0, presalePrice - 1, maxSupply - 2, maxPerAddress - 3, presaleMaxPerAddress - 4, publicSaleTime - 5, _preSaleTime - 6, _maxTxPerAddress - 7
        bytes32 merkleRoot,
        address[] memory payees,
        uint256[] memory shares,
        address royaltyRecipient,
        uint256 royaltyAmount
    )
Updated: See error below ->
Running 'scripts/deploy.py::main'...
  File "brownie/_cli/run.py", line 51, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 110, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/deploy.py", line 48, in main
    deploy_turtles()
  File "./scripts/deploy.py", line 13, in deploy_turtles
    turtle_deployed = Turtles.deploy(
  File "brownie/network/contract.py", line 549, in __call__
    return tx["from"].deploy(
  File "brownie/network/account.py", line 509, in deploy
    data = contract.deploy.encode_input(*args)
  File "brownie/network/contract.py", line 579, in encode_input
    data = format_input(self.abi, args)
  File "brownie/convert/normalize.py", line 20, in format_input
    raise type(e)(f"{abi['name']} {e}") from None
ValueError: constructor '['0x4a40E425a8D1EE6279f860d8fd5db3D3661558d6', '0xa9873c4c5FBd0196d0fbA2e50a3eEe216C4D6780']' - '['0x4a40E425a8D1EE6279f860d8fd5db3D3661558d6', '0xa9873c4c5FBd0196d0fbA2e50a3eEe216C4D6780']' is not a valid ETH address

Ur addresses needs to be in a checkSum format. Ur 地址需要采用checkSum格式。

Do this:做这个:

address1=web3.toChecksumAddress(*your address*)
address2=web3.toChecksumAddress(*your address*)

EDIT:编辑:

turtle_deployed = Turtles.deploy(
        "Turtles",
        "Turtle",
        "ipfs://bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354/",
        [100, 10, 20000, 20, 10, 1655480363, 1655473254, 100],
        "ea58dfa481a0c08b4af0417e3f62244215a1ab1eae0a100da48407be5cdd94b7",
        addresses,
        [10, 15],
        addresses,  <-- **THIS is suppose to be an Address, not a list of Address**
        700,
        {"from": account},
        publish_source=True,
    )

The last addresses input need to be a single address, not a list of addresses最后输入的地址需要是单个地址,而不是地址列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM