1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error: call exception in ethers.js

Discussion in 'Finance' started by user714171, Oct 8, 2018.

  1. user714171

    user714171 Guest

    This one has really stumped me. Any help would be great!

    I'm fetching lots of data from etherum using Ethers.js. Everything works fine when I'm returning arrays shorter than 300 ints, but when return more than 300 or so ints in an array I get this error:

    { Error: call exception (address="0xf795b19A47FC82361F766DAD69849755C18b529d", method="getTimestampsFromPublishers(address[],string[],int256[],bool,uint256)", args=[["0xfa3c01ef86f30ad8d4668ede34b4a49798604191"],[],[],true,350])
    at Object.throwError (/Users/arc/Documents/Etherum/subby.js/node_modules/ethers/utils/errors.js:68:17)
    at /Users/arc/Documents/Etherum/subby.js/node_modules/ethers/contracts/contract.js:118:36
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    reason: 'call exception',
    code: 'CALL_EXCEPTION',
    address: '0xf795b19A47FC82361F766DAD69849755C18b529d',
    method: 'getTimestampsFromPublishers(address[],string[],int256[],bool,uint256)',
    args:
    [ [ '0xfa3c01ef86f30ad8d4668ede34b4a49798604191' ],
    [],
    [],
    true,
    350 ] }


    Remix is of no help since it crashes before returning anything. When I try the same call using web3 v 1.0 instead Ethers.js I get empty arrays instead of an error. Also web3 1.0 fails to return arrays longer than even 10 ints. So this leads me to believe that this is not a gas problem...

    I'm connecting to Etherum like this:

    let provider = new ethers.providers.InfuraProvider('rinkeby');
    let account0PrivateKey = 'lasdfjlsladkf234234234asldjfa23sdflsdj'
    let account0Wallet = new ethers.Wallet(account0PrivateKey, provider)

    const contractAddress = '0xf795b19A47FC82361F766DAD69849755C18b529d'
    subby = new ethers.Contract(contractAddress, abi, account0Wallet)


    This is the contract that is failing:

    pragma experimental ABIEncoderV2;


    contract Test {

    mapping(address => uint[]) public addressToTimestamps;
    mapping(string => address) private usernameToAddress;


    // ["0xca35b7d915458ef540ade6068dfe2f44e8fa733c"], 20
    function createMockTimestamps(address[] addresses, uint amount) public {
    for (uint i = 0; i < addresses.length; i++) {
    for (uint j = 0; j < amount; j++) {
    addressToTimestamps[addresses].push(now);
    }
    }
    }

    function getTimestamp(address _address, uint id) internal view returns (uint) {
    uint[] memory timestamps = addressToTimestamps[_address];
    if (timestamps.length > id) {
    return timestamps[id];
    }
    else {
    return 0;
    }
    }

    function getAddressesFromUsernames(string[] names) public view returns (address[]) {
    address[] memory returnAddresses = new address[](names.length);
    for (uint i = 0; i < names.length; i++) {
    returnAddresses = usernameToAddress[names];
    }
    return returnAddresses;
    }

    // ["0xca35b7d915458ef540ade6068dfe2f44e8fa733c"], [], [], true, 20
    function getTimestampsFromPublishers(address[] addresses, string[] usernames, int[] startAt, bool startAtLatestPost, uint limit)
    public view returns (uint[], uint[]) {
    address[] memory addressesFromUsernames;
    if (usernames.length > 0) {
    addressesFromUsernames = getAddressesFromUsernames(usernames);
    }
    uint[] memory timestamps = new uint[]((addresses.length + addressesFromUsernames.length) * limit);

    getTimestamps(timestamps, addresses, startAt, startAtLatestPost, limit, 0);
    getTimestamps(timestamps, addressesFromUsernames, startAt, startAtLatestPost, limit, addresses.length);

    return (timestamps, getTimestampLengths(addresses, addressesFromUsernames));
    }

    function getTimestamps(uint[] timestamps, address[] addresses, int[] startAt, bool startAtLatestPost, uint limit, uint count) internal view {
    for (uint i = 0; i < addresses.length; i++) {
    address _address = addresses;
    int start;
    if (startAtLatestPost) {
    start = int(addressToTimestamps[addresses].length - 1);
    } else {
    start = startAt;
    }
    for (uint j = 0; j < limit; j++) {
    if (start >= 0) {
    timestamps[count] = getTimestamp(_address, uint(start) - j);
    } else {
    timestamps[count] = 0;
    }
    count++;
    }
    }
    }

    function getTimestampLengths(address[] addressesOne, address[] addressesTwo) internal view returns (uint[]) {
    uint[] memory timestampLengths = new uint[](addressesOne.length + addressesTwo.length);
    uint count = 0;
    for (uint i = 0; i < addressesOne.length; i++) {
    timestampLengths[count] = addressToTimestamps[addressesOne].length;
    }
    for (i = 0; i < addressesTwo.length; i++) {
    timestampLengths[count] = addressToTimestamps[addressesTwo].length;
    }
    return timestampLengths;
    }

    }

    Login To add answer/comment
     

Share This Page