1、BSC链
2、代码: ids_uint256 = self.w3.toInt(int(2)) amount_uint256 = self.w3.toInt(int(1)) txn = self.contract.functions.batchRegister(ids_uint256, amount_uint256).call() txn1 = txn.buildTransaction({ "chainId": self.w3.eth.chain_id, "from": wallet, "nonce": self.w3.eth.getTransactionCount(self.wallet), "gasPrice": self.w3.eth.gas_price }) signed_txn = self.w3.eth.account.sign_transaction(txn1, private_key) txn_hash = self.w3.eth.send_raw_transaction(signed_txn.rawTransaction) txn_hash = self.w3.toHex(txn_hash)
其中到 txn = self.contract.functions.batchRegister(ids_uint256, amount_uint256).call() 这行代码就出错。
3、报错内容:
web3.exceptions.ValidationError:
Could not identify the intended function with name batchRegister
, positional argument(s) of type (<class 'int'>, <class 'int'>)
and keyword argument(s) of type {}
.
Found 1 function(s) with the name batchRegister
: ['batchRegister(uint256[],uint256[])']
Function invocation failed due to no matching argument types.
4、尝试过的办法: batchRegister方法调用的两个值ids和amount要求uint256格式,但是怎么转换成这种格式?我之前一直用 web3.toWei 或者 web3.toInt,但是这次一直不行。 不论是class int,class str……等都用不了
我就想问 Web3.py 有转换成uint256的指令吗?