Solidity

web3.py - 帶有 int256 的合約函式的 Python dtypeXXx

  • March 13, 2018

假設我有這個範例契約:

pragma solidity ^0.4.0;
contract SEexample {

   int256[3] thing;
   uint8 internal i=0;

   function submit(int256[3] bids,int256[3] prefs) public returns (int256[3]){
           for (i=0;i<3;i++){
               thing[i] = bids[i] + prefs[i];
           }
       return thing;
   }
}

給這個 abi:

[
   {
       "constant": false,
       "inputs": [
           {
               "name": "bids",
               "type": "int256[3]"
           },
           {
               "name": "prefs",
               "type": "int256[3]"
           }
       ],
       "name": "submit",
       "outputs": [
           {
               "name": "",
               "type": "int256[3]"
           }
       ],
       "payable": false,
       "stateMutability": "nonpayable",
       "type": "function"
   }
]

我使用 web3.py 進行部署:

from web3 import Web3, HTTPProvider, IPCProvider
w3 = Web3(HTTPProvider('http://localhost:8545'))   //(testrpc)
tx_hash = contract.deploy(transaction={'from': w3nce.eth.accounts[0], 'gas': 10000000})
tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
contract_address = tx_receipt['contractAddress']
contract_instance = w3.eth.contract(address=contract_address, abi=abi, ContractFactoryClass=ConciseContract)

我如何指示python滿足int256$$ 13 $$該功能需要什麼?

我嘗試了以下變化:

import numpy as np
a=np.ones((3,),dtype=int)
b=np.ones((3,),dtype=int)
x=contract_instance.submit(a,b, transact={'from': w3.eth.accounts[1]})

也與a.tobytes(),b.tobytes()

結果是 :

raise ValueError("No matching functions found")

ValueError:找不到匹配的函式

這似乎有效:

x=contract_instance.submit(a.tolist(),b.tolist(), transact={'from': w3.eth.accounts[1]})

引用自:https://ethereum.stackexchange.com/questions/42624