今まではRemixかTruffleを使って、SmartcontractのDeployを実行していました。
PythonでDeploy出来ればいいなと思い、py-solc-xを使うことにしました。
そこで起きた問題が解決出来ずに、今回お力を貸していただきたいです。
pythonから抜粋
compile_source(source, output_values=["abi", "bin"], solc_version=_solc_version)
中略
tx = contract.constructor("Hi!").build_transaction(
dict(
chainId=web3_connect.connect_provider["chain_id"],
nonce=w3.eth.getTransactionCount(FROM_ADDRESS),
type=2,
gas=1000000,
maxFeePerGas=web3_connect.gwei_to_wei(math.ceil(gas_station["maxFee"])),
maxPriorityFeePerGas=web3_connect.gwei_to_wei(math.ceil(gas_station["maxPriorityFee"])),
)
)
solidity
pragma solidity ^0.8.0;
contract Test {
string public msg;
constructor(string memory message) {
msg = message;
}
function greet() public view returns (string memory) {
return msg;
}
}
上記のケースでは正常にdeployすることが出来ました。
solidityに新たなVersionクラスを追加し継承させました。
pragma solidity ^0.8.0;
contract Version {
string private _version;
constructor(string memory version_) {
_version = version_;
}
function version() external view returns (string memory) {
return _version;
}
}
contract Test is Version {
string public msg;
constructor(string memory message, string memory version) Version(version) {
msg = message;
}
function greet() public view returns (string memory) {
return msg;
}
}
constructorの引数が増えているので、pythonを以下のように変更しました。
tx = contract.constructor("Hi!", "1.0.0").build_transaction(
dict(
chainId=web3_connect.connect_provider["chain_id"],
nonce=w3.eth.getTransactionCount(FROM_ADDRESS),
type=2,
gas=1000000,
maxFeePerGas=web3_connect.gwei_to_wei(math.ceil(gas_station["maxFee"])),
maxPriorityFeePerGas=web3_connect.gwei_to_wei(math.ceil(gas_station["maxPriorityFee"])),
)
)
このpythonを実行するとエラーになりました。
"Incorrect argument count. Expected '1'. Got '2'"
abiを取得すると、Versionクラスの分のみとなっているため、引数の数が一致しないということまではわかりました。
remixだとどのクラスをコンパイルするか指定できますが、py-solc-xでも同じように出来ないでしょうか?
もしくはVersionクラスの書き方が良くないのか、どなたかご存じないでしょうか。