web3.py Konstruktor (Adresstyp)

Ich habe versucht, den Vertrag auf meinem TestrPC bereitzustellen, aber ich erhalte eine Fehlermeldung, wenn mein Konstruktor den Typ „Adresse“ verwendet.

Hier ist mein 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'],
)
Ich habe schließlich '' valid_address = w3.toChecksumAddress(questionable_address) '' verwendet und es funktioniert.

Antworten (1)

Ich habe endlich verwendet valid_address = w3.toChecksumAddress(questionable_address)und es funktioniert.

Ich nehme an, Sie haben die Adresse "0xc69d7e6739e30796f1cc7a1a01fd0c087c4e54fd"aus dieser Zeile konvertiert:

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

Das Problem ist, dass Sie durch eine Konvertierung auf diese Weise keinen Nutzen aus der Prüfsumme ziehen können. Es scheint, dass Sie die Adresse von irgendwoher kopiert/eingetippt haben, und wenn Sie sie falsch kopiert haben, soll die Prüfsumme Ihnen helfen, sie zu finden.

Woher stammt die Adresse? Die meisten Quellen sollten die Adresse jetzt im Prüfsummenformat anzeigen. Wenn sie dies nicht können oder nicht tun, wäre es sehr vernünftig, ein Problem zu melden und den Support anzufordern.

Danke für die Antwort, ich habe das Fehlerprotokoll zuerst nicht bemerkt. Die Adresse stammt von testrpc