0

I'm getting a strange error when trying to get_table_rows...

    <script src='/wp-content/themes/oceanwp/assets/beta3/eosjs-api.js'></script>
    <script src='/wp-content/themes/oceanwp/assets/beta3/eosjs-jsonrpc.js'></script>
    <script src='/wp-content/themes/oceanwp/assets/js/scatterjs-core.min.js'></script> 
    <script src='/wp-content/themes/oceanwp/assets/js/scatterjs-plugin-eosjs2.min.js'></script> 
    <script src='/wp-content/themes/oceanwp//assets/beta2-/eosjs-debug.js'></script>
    <script src='/wp-content/themes/oceanwp//assets/beta2-/eosjs-jsonrpc-debug.js'></script>
    <script src='/wp-content/themes/oceanwp//assets/js/scatterjs-plugin-lynx.min.js'></script>
    
 
    

const rpc = new eosjs_jsonrpc.JsonRpc('https://uxnetwork.io', {});
        //  console.log(rpc);
        let accountWorb = document.getElementById('worbaccount').value;
          console.log(accountWorb); 
        try {
        (async () => {

        console.log(rpc.get_table_rows({
            json: false,                 // Get the response as json
            code: 'genesis11143',           // Contract that we target
            scope: 'genesis11143',          // Account that owns the data
            table: 'worbliclaim',          // Table name
            lower_bound: accountWorb,     // Table primary key value
            limit: 1,                     // limit to 1 to get only the single row
            reverse: false,             // Optional: Get reversed data
            show_payer: false,          // Optional: Show ram payer
        }));
    })();
            } catch(e) {
                console.log("Error", e); 
            }
    }

The error is happening in eosjs-jsonrpc on line 130

 /** Post `body` to `endpoint + path`. Throws detailed error information in `RpcError` when available. */
    public async fetch(path: string, body: any) {
        let response;
        let json;
        try {
            const f = this.fetchBuiltin;
            response = await f(this.endpoint + path, {
                body: JSON.stringify(body),
                method: "POST",
            });
            json = await response.json();   <<<<=== ERROR: canot read property json of undefined                  
            if (json.processed && json.processed.except) {
                throw new RpcError(json);
            }
        } catch (e) {
            e.isFetchError = true;
            throw e;
        }
        if (!response.ok) {
            throw new RpcError(json);
        }
        return json;
    }

Hopefully, the answer is simple to someone, Thank you!

2
  • 1
    You need to call get_table_rows with option json: true. Your code sets it to false. – conr2d Sep 11 '20 at 1:17
  • I agree, except that doesn't fix the issue. I flipped it to false in an attempt to work around the issue, and forgot to flip it back before posting. Sorry for not adding the "things I tried" to the post. But thank you very much for looking at this – Greg Simpson Sep 11 '20 at 13:28

Your Answer

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

Browse other questions tagged or ask your own question.