Solidity

值錯誤:使用 web3.py 呼叫 1inch 合約但 ABI 出現問題

  • January 11, 2021

我正在嘗試從 1inch 獲取有關乙太坊/DAI 價格的報價。我是 Web3.py 的新手,需要一些關於以下問題的額外幫助。

我的程式碼:

import json
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/<My Infura ID>'))

one_inch_split_abi = json.load(open('abi/one_inch_split.json', 'r'))
mcd_abi = json.load(open('abi/mcd_join.json', 'r'))

base_account = "0xA5E421c63b2314ae93c20D5f6021De44DF650b56"

def one_inch_get_quote(_from_token, _to_token, _amount):
   '''
   Get quote data from one inch split contract using on-chain call
   '''
   # load our contract
   one_inch_join = w3.eth.contract(
       address=one_inch_split_contract, abi=one_inch_split_abi)

   # make call request to contract on the Ethereum blockchain
   contract_response = one_inch_join.functions.getExpectedReturn(
       _from_token, _to_token, _amount, 100, 0).call({'from': base_account})

   # logger.info("contract response: {0}".format(contract_response))
   return contract_response

mcd_contract_address = w3.toChecksumAddress('0x6b175474e89094c44da98b954eedeac495271d0f')  # DAI Token contract address

ethereum = w3.toChecksumAddress('0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE') # Ethereum address

one_inch_split_contract = w3.toChecksumAddress('0xC586BeF4a0992C495Cf22e1aeEE4E446CECDee0E') # 1inch address


ethereum_price = one_inch_get_quote(ethereum, mcd_contract_address, w3.toWei(1, 'ether'))

print(ethereum_price)

使用 python 中的此程式碼,我收到以下錯誤消息:

ValueError:無法格式化值 {“這是 1 英寸 ABI 中的程式碼”}

更新:我導入了無效的 ABI。請確保您的 ABI 程式碼包含在

$$ $$.

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