Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

indicate ValueError: No matching functions found when call function contained in abi json file #875

Open
FrancisJen opened this issue May 8, 2018 · 0 comments

Comments

@FrancisJen
Copy link

indicate ValueError: No matching functions found.

I wanted to deposit some ETH to contract address by calling the ABI method named ‘deposit’, maybe the method was not found by the program.

below is the ABI file and my program, Please help me out~

[Error]:

Traceback (most recent call last):
File “/Users/xxx/Project/py3interface/util/connect_kovan.py”, line 126, in
kovan.send_ether_to_contract(0.0001)
File “/Users/renyiguang/Project/py3interface/util/connect_kovan.py”, line 90, in send_ether_to_contract
txn_dict = self.R1.functions.deposit(self.wallet_address, amount_in_ether).buildTransaction({

File “/Users/xxx/.virtualenvs/py3interface-rXFxZXWO/lib/python3.6/site-packages/web3/utils/contracts.py”, line 100, in find_matching_fn_abi
raise ValueError(“No matching functions found”)
ValueError: No matching functions found

[code]:

coding=utf-8

from web3 import Web3, HTTPProvider, contract
import json
import time
from data import contract_abi

class OperationKovan:
def init(self):

    self.url = 'https://kovan.infura.io'
    self.w3 = Web3(HTTPProvider(self.url))

    # 前端充值
    self.R1_CONTRACT_ADDRESS = 'XXX'
    # with open(self.R1_CONTRACT_PATH) as load_f:
    #     abi = json.load(load_f)
    # print(abi)
    self.wallet_address = 'xxx'
    self.wallet_private_key = 'xxx'

    # 创建R1对象(合约对象)
    self.R1 = self.w3.eth.contract(address=self.R1_CONTRACT_ADDRESS, abi=contract_abi.abi)
    print(contract_abi.abi)

    self.w3.eth.enable_unaudited_features()

# 获得区块高度
def get_block_num(self):
    block_number = self.w3.eth.blockNumber
    return block_number

# 通过合约对象的xx方法获取到充值所需的数据
def get_recharge_data(self):
    pass

def send_xxx_to_contract(self, amount_in_ether):

    amount_in_wei = self.w3.toWei(amount_in_ether, 'ether')

    nonce = self.w3.eth.getTransactionCount(self.wallet_address)

    a = self.R1.functions.deposit
    print(a)
    print('----------')

    txn = self.R1.functions.deposit(
        self.wallet_address, 1,
    ).buildTransaction({
        'chainId': 42,
        'gas': 170000,
        'value': amount_in_wei,
        'gasPrice': self.w3.toWei('1', 'gwei'),
        'nonce': nonce,
    })

    signed_txn = self.w3.eth.account.signTransaction(txn, self.wallet_private_key)
    txn_hash = self.w3.eth.sendRawTransaction(signed_txn.rawTransaction)
    txn_receipt = None
    count = 0
    while txn_receipt is None and (count < 30):
        txn_receipt = self.w3.eth.getTransactionReceipt(txn_hash)
        print(txn_receipt)
        time.sleep(10)

    if txn_receipt is None:
        return {'status': 'failed', 'error': 'timeout'}

    return {'status': 'added', 'txn_receipt': txn_receipt}

def send_ether_to_contract(self, amount_in_ether):
    amount_in_wei = self.w3.toWei(amount_in_ether, 'ether')

    nonce = self.w3.eth.getTransactionCount(self.wallet_address)

    # txn_dict = {
    #         'to': self.R1_CONTRACT_ADDRESS,
    #         'value': amount_in_wei,
    #         'gas': 2000000,
    #         'gasPrice': self.w3.toWei('40', 'gwei'),
    #         'nonce': nonce,
    #         'chainId': 42       #chainID list: https://ethereum.stackexchange.com/questions/17051/how-to-select-a-network-id-or-is-there-a-list-of-network-ids
    # }

    txn_dict = self.R1.functions.deposit(self.wallet_address, amount_in_ether).buildTransaction({
        'chainId': 42,
        'gas': 140000,
        'gasPrice': self.w3.toWei('40', 'gwei'),
        'nonce': nonce,
    })

    signed_txn = self.w3.eth.account.signTransaction(txn_dict, self.wallet_private_key)

    result = self.w3.eth.sendRawTransaction(signed_txn.rawTransaction)

    tx_receipt = self.w3.eth.getTransactionReceipt(result)

    count = 0

    # loop for transaction is included in a block
    while tx_receipt is None and (count < 30):

        tx_receipt = self.w3.eth.getTransactionReceipt(result)

        print(tx_receipt)

        time.sleep(10)
        print(count)

    if tx_receipt is None:
        return {'status': 'failed', 'error': 'timeout'}

    return {'status': 'added', 'txn_receipt': tx_receipt}

if name == 'main':
kovan = OperationKovan()
blockNum = kovan.get_block_num()
print(blockNum)
# recharge
kovan.send_ether_to_contract(0.0001)
[abi python file]:
abi = """[
{
"constant": true,
"inputs": [],
"name": "withdrawEnabled",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
},
{
"name": "",
"type": "address"
}
],
"name": "withdrawAllowance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "token",
"type": "address"
},
{
"name": "amount",
"type": "uint256"
}
],
"name": "depositToken",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "bytes32"
}
],
"name": "withdrawn",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "addresses",
"type": "address[11][]"
},
{
"name": "values",
"type": "uint256[10][]"
},
{
"name": "v",
"type": "uint8[2][]"
},
{
"name": "r",
"type": "bytes32[2][]"
},
{
"name": "s",
"type": "bytes32[2][]"
}
],
"name": "batchTrade",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "admins",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "admin",
"type": "address"
},
{
"name": "isAdmin",
"type": "bool"
}
],
"name": "setAdmin",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
},
{
"name": "",
"type": "bytes32"
}
],
"name": "buyOrderFilled",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "addresses",
"type": "address[11]"
},
{
"name": "values",
"type": "uint256[10]"
},
{
"name": "v",
"type": "uint8[2]"
},
{
"name": "r",
"type": "bytes32[2]"
},
{
"name": "s",
"type": "bytes32[2]"
}
],
"name": "trade",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
},
{
"name": "",
"type": "address"
}
],
"name": "latestApply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "token",
"type": "address"
},
{
"name": "amount",
"type": "uint256"
}
],
"name": "withdrawNoLimit",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "addresses",
"type": "address[3]"
},
{
"name": "values",
"type": "uint256[3]"
},
{
"name": "v",
"type": "uint8"
},
{
"name": "r",
"type": "bytes32"
},
{
"name": "s",
"type": "bytes32"
}
],
"name": "adminWithdraw",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "acceptOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "enabled",
"type": "bool"
}
],
"name": "enableWithdraw",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "lock",
"type": "uint256"
}
],
"name": "changeLockTime",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "feeRate",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "acc",
"type": "address"
},
{
"name": "asFee",
"type": "bool"
}
],
"name": "setFeeAccount",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "token",
"type": "address"
},
{
"name": "amount",
"type": "uint256"
}
],
"name": "applyWithdraw",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_newOwner",
"type": "address"
}
],
"name": "changeOwner",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "tokenBuy",
"type": "address"
},
{
"name": "amountBuy",
"type": "uint256"
},
{
"name": "tokenSell",
"type": "address"
},
{
"name": "amountSell",
"type": "uint256"
},
{
"name": "base",
"type": "address"
},
{
"name": "expires",
"type": "uint256"
},
{
"name": "nonce",
"type": "uint256"
},
{
"name": "feeToken",
"type": "address"
}
],
"name": "getOrderHash",
"outputs": [
{
"name": "",
"type": "bytes32"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "fr",
"type": "uint256"
}
],
"name": "changeFeeRate",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "user",
"type": "address"
},
{
"name": "tokens",
"type": "address[]"
}
],
"name": "refund",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "token",
"type": "address"
},
{
"name": "user",
"type": "address"
}
],
"name": "approveWithdraw",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "deposit",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
},
{
"name": "",
"type": "address"
}
],
"name": "applyList",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
},
{
"name": "",
"type": "address"
}
],
"name": "tokenList",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "feeAccounts",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
},
{
"name": "",
"type": "bytes32"
}
],
"name": "sellOrderFilled",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "hash",
"type": "bytes32"
},
{
"name": "v",
"type": "uint8"
},
{
"name": "r",
"type": "bytes32"
},
{
"name": "s",
"type": "bytes32"
}
],
"name": "verify",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "applyWait",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "token",
"type": "address"
},
{
"name": "amount",
"type": "uint256"
}
],
"name": "withdraw",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "token",
"type": "address"
},
{
"name": "user",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "VERSION",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"payable": false,
"stateMutability": "nonpayable",
"type": "fallback"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "token",
"type": "address"
},
{
"indexed": false,
"name": "user",
"type": "address"
},
{
"indexed": false,
"name": "amount",
"type": "uint256"
},
{
"indexed": false,
"name": "balance",
"type": "uint256"
}
],
"name": "Deposit",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "token",
"type": "address"
},
{
"indexed": false,
"name": "user",
"type": "address"
},
{
"indexed": false,
"name": "amount",
"type": "uint256"
},
{
"indexed": false,
"name": "balance",
"type": "uint256"
}
],
"name": "Withdraw",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "token",
"type": "address"
},
{
"indexed": false,
"name": "user",
"type": "address"
},
{
"indexed": false,
"name": "amount",
"type": "uint256"
},
{
"indexed": false,
"name": "time",
"type": "uint256"
}
],
"name": "ApplyWithdraw",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "_prevOwner",
"type": "address"
},
{
"indexed": false,
"name": "_newOwner",
"type": "address"
}
],
"name": "OwnerUpdate",
"type": "event"
}
]"""

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant