简体   繁体   English

从Web3.py部署与OpenZeppelin签订的合同

[英]Deploy contract made with OpenZeppelin from Web3.py

I've followed a tutorial centered in the creation of an ICO and a Crowdsale (based on the ICO that I've created). 我遵循了一个以ICO和Crowdsale(基于我创建的ICO)的创建为中心的教程。

It's a very classic tutorial, I know, but now I'm integrating the 2 contracts made with the help of OpenZeppelin and Truffle framework in a Django platform with the Web3.py library, and I'm encountering a problem. 我知道这是一个非常经典的教程,但是现在我将在Web3.py库的Django平台中集成了在OpenZeppelin和Truffle框架的帮助下达成的2个合同,但遇到了问题。

I've compiled the contract sources with solc, and I've obtained the abi and bin files. 我已经用solc编译了合同来源,并且获得了abi和bin文件。

I've opened the files like this in python 我已经在python中打开了像这样的文件

with open("reservations/contracts/compiled/GustavoCoin.abi") as contract_abi_file_coin:
    contract_abi_coin = json.load(contract_abi_file_coin)

with open("reservations/contracts/compiled/GustavoCoin.bin") as contract_bin_file_coin:
    contract_bytecode_coin = '0x' + contract_bin_file_coin.read()

with open("reservations/contracts/compiled/GustavoCoin.abi") as contract_abi_file:
    contract_abi = json.load(contract_abi_file)

with open("reservations/contracts/compiled/GustavoCoinCrowdsale.bin") as contract_bin_file:
    contract_bytecode = '0x' + contract_bin_file.read()

I've also initializated the Coin contract in Ganache blockchain emulator. 我还已经在Ganache区块链模拟器中初始化了Coin合同。

But now I don't know how deploy the Crowdsale contract in the blockchain. 但是现在我不知道如何在区块链中部署Crowdsale合同。

Here is the successful code for deploying the coin: 这是部署硬币的成功代码:

contract_coin = w3.eth.contract(abi=contract_abi_coin, bytecode=contract_bytecode_coin)

tx_param = {
    'from': w3.eth.accounts[1],
    'gasPrice': 2000,
}
tx_hash = contract_coin.deploy(transaction=tx_param)

Here is the failing code for deploying the crowdsale contract: 这是部署众包合同的失败代码:

construct_crowdsale = contract.constructor(11, 11, 1, w3.eth.accounts[1], tx_receipt.contractAddress)
crowdsale_txn_hash = construct_crowdsale.transact()

This deploy generates a ganache error: 此部署会产生ganache错误:

error vm exception while processing transaction revert 处理事务还原时出错vm异常

Any ideas how to correctly deploy in web3.py? 有什么想法如何正确地部署在web3.py中吗?


As a reference point, here is the successful code to deploy the crowdsale code with Truffle framework: 作为参考,下面是使用Truffle框架部署众筹代码的成功代码:

return deployer
    .then(() => {
        return deployer.deploy(GustavoCoin);
    })
    .then(() => {
        return deployer.deploy(
            GustavoCoinCrowdsale,
            openingTime,
            closingTime,
            rate,
            wallet,
            GustavoCoin.address
        );
    });
};

When sending the deployment, remember to set important transaction fields. 发送部署时,请记住设置重要的交易字段。 For example, you might set account that the transaction should be signed with. 例如,您可以设置用于进行交易签名的帐户。 That means replacing the current line: 这意味着替换当前行:

crowdsale_txn_hash = construct_crowdsale.transact()

with the new lines: 用新行:

tx_param = {
    'from': w3.eth.accounts[1],
    'gasPrice': 2000,
}
crowdsale_txn_hash = construct_crowdsale.transact(tx_param)

Note that this is analogous to the way that the sender was set in the coin contract (using the older deploy() API): 请注意,这类似于在硬币合约中设置发送者的方式(使用较旧的deploy() API):

tx_param = {
    'from': w3.eth.accounts[1],
    'gasPrice': 2000,
}
tx_hash = contract_coin.deploy(transaction=tx_param)

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

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