2

I tried to deploy the contract on my testrpc, but I get error when my constructor using "address" type.

Here is my python code:

import json
import web3
from solc import compile_source
from web3.contract import ConciseContract
from web3 import Web3, EthereumTesterProvider
from web3.auto import w3

w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545"))

# Solidity source code
contract_source_code = '''
pragma solidity ^0.4.23;
contract Demo2{

    address public owner = msg.sender;
    address[] user;
    address Bank1;

    constructor (string _ID ,address _addr ) {
    }
}

'''

compiled_sol = compile_source(contract_source_code) # Compiled source code
contract_interface = compiled_sol['<stdin>:Demo2']
w3.eth.defaultAccount = w3.eth.accounts[0]
a=type(w3.eth.accounts[0])
print(a)

Demo2 = w3.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])
ab=contract_interface['abi']
print(ab)
# Submit the transaction that deploys the contract
tx_hash = Demo2.constructor("abcde","0xc69d7e6739e30796f1cc7a1a01fd0c087c4e54fd").transact()

# Wait for the transaction to be mined, and get the transaction receipt
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)

# Create the contract instance with the newly-deployed address
Demo2 = w3.eth.contract(
    address=tx_receipt.contractAddress,
    abi=contract_interface['abi'],
)
  • I finally used '' valid_address = w3.toChecksumAddress(questionable_address) '' and it works. – hhh2012aa Aug 20 '18 at 15:02
0

I finally used valid_address = w3.toChecksumAddress(questionable_address) and it works.

I assume you were converting the address "0xc69d7e6739e30796f1cc7a1a01fd0c087c4e54fd" from this line:

Demo2.constructor("abcde","0xc69d7e6739e30796f1cc7a1a01fd0c087c4e54fd")

The problem is that a conversion this way prevents you from getting any benefit from the checksum. It seems that you copied/typed in the address from somewhere, and if you copied it incorrectly, the checksum is supposed to help you catch it.

Where did the address come from? Most sources should display the address in checksum format now. If they can't or don't, it would be very reasonable to file an issue asking for the support.

| improve this answer | |
  • Thanks for the answer,I didn't notice the error log at first . The address is from testrpc – hhh2012aa Aug 21 '18 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.