在BSC链上合约方法调用时出现错误,提示:uint256[]不匹配——尝试toWei,toInt,toBytes等都无法解决,请教应该怎么弄?

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的指令吗?

请先 登录 后评论

最佳答案 2023-02-07 14:00

看错误提示参数是数组啊,你试试这样看行不行:

ids_uint256 = [self.w3.toInt(int(2))]
amount_uint256 = [self.w3.toInt(int(1))]
txn = self.contract.functions.batchRegister(ids_uint256, amount_uint256).call()
请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 0 收藏,1981 浏览
  • bfund 提出于 2023-02-06 22:16