i am trying to get the quote from 1inch regarding the Ethereum/DAI price. I am new to Web3.py and need some additional help regarding the following problem.

My code:

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'))


With this code in python i get the following error message:

ValueError: Could not format value {"Here is the code within the 1inch ABI"}


Update: I had an invalid ABI imported. Please make sure that your ABI code is wrapped within [].

  • Excellent. Remember to come back and mark your answer as correct. You can do it after a day or so. Jan 11 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.