0
votes

I've followed a tutorial centered in the creation of an ICO and a Crowdsale (based on the ICO that I've created).

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.

I've compiled the contract sources with solc, and I've obtained the abi and bin files.

I've opened the files like this in 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.

But now I don't know how deploy the Crowdsale contract in the blockchain.

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:

error vm exception while processing transaction revert

Any ideas how to correctly deploy in web3.py?


As a reference point, here is the successful code to deploy the crowdsale code with Truffle framework:

return deployer
    .then(() => {
        return deployer.deploy(GustavoCoin);
    })
    .then(() => {
        return deployer.deploy(
            GustavoCoinCrowdsale,
            openingTime,
            closingTime,
            rate,
            wallet,
            GustavoCoin.address
        );
    });
};
1
Why can don't you just use the same code you used for the coin contract? I don't see a reason why it wouldn't work? Or am I missing something?nikos fotiadis
I've inserted this parameters in the constructor: tx_hash_prova = contract.constructor(11, 11, 1, w3.eth.accounts[1], tx_receipt.contractAddress).transact(), the last parameter is the address of the coin contract, then when I deploy it I encounter an errorFlamel
The error involves the ganache blockchain emulator that says: error vm exception while processing transaction revertFlamel
Try following the instructions on this answer. It is a slightly different approach. ethereum.stackexchange.com/questions/44614/…nikos fotiadis

1 Answers

0
votes

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):

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