secretkeylabs / sats-connect

Sats connect is a simple javascript library that connects apps to Bitcoin wallets
https://www.npmjs.com/package/sats-connect
100 stars 36 forks source link

[bug] Xverse ord_getInscriptions Internal JSON-RPC error (-32603) #165

Open astralarkitekt opened 3 weeks ago

astralarkitekt commented 3 weeks ago

Is there an existing issue for this?

SATS-CONNECT Version

2.6.0

Current Behavior

ord_getInscriptions() call is returning an error code -32603 (Internal JSON RPC error)

In our Vue 3 app we use a Pinia Store for interacting with sats-connect.

We first call and get a success from:

const response = await Wallet.request('getAccounts', {
          purposes: [AddressPurpose.Ordinals],
          message: 'Please sign this message to verify ownership of your wallet and assets.'
        });

Then we attempt to fetch the inscriptions based on the provider ... in this case Xverse...

 const inscriptions = await Wallet.request('ord_getInscriptions', {
          offset,
          limit: 60
        });

This results in the following response from sats-connect:

{
    "status": "error",
    "error": {
        "code": -32603,
        "message": "Internal error."
    }
}

According to the Docs - this is an Internal JSON-RPC error.

This code worked a little over a week ago. I have made no changes to my application and now it does NOT work. All calls to xverse's ord_getInscriptions() with my wallet result in this error. This is consistent across various

Expected Behavior

I expect to receive a list of up to 60 inscriptions.

Steps To Reproduce

Install sats-connect.

Follow the above steps in the current behavior section.

Link to Minimal Reproducible Example (CodeSandbox, StackBlitz, etc.)

No response

Anything else?

No response

aryzing commented 3 weeks ago

Thanks for reporting @astralarkitekt, to help debug the issue, could you please try using sats-connect 2.7.0 to see if that helps?

If that doesn't help, try clearing the service worker's storage: clear-storage.webm

Let me know if / what worked for you

danilomarcus commented 1 week ago

Hello friends, I am facing the same issue:

This is the code I am using:

try {
        const response = await request("wallet_requestPermissions", undefined);
        console.log(response);

        let address = '0';
        let balance = [];
        let runes = [];
        let inscriptions = [];
        let accounts = [];

        if (response.status === 'success') {
            const info = await Wallet.request("getInfo", null);
            console.log(info);

            accounts = await Wallet.request('getAccounts',
                {
                    purposes: ['ordinals', 'payment', 'stacks'],
                    message: 'Welcome to My Page'
                }
            );
            console.log(accounts);

            if (accounts.status === 'success') {

                address = accounts.result[0].address;
                console.log('your wallet is: ' + address);

                // get all the wallets (0=ordinals, 1=payment, 2=stacks)
                accounts = accounts.result;

                balance = await Wallet.request("getBalance", undefined);
                if (balance.status === 'success') {
                    console.log(balance);
                    balance = balance.result;
                } else {
                    console.error(balance.error);
                    balance = [];
                }

                runes = await Wallet.request("runes_getBalance", null);
                if (runes.status === 'success') {
                    console.log(runes);
                    runes = runes.result;
                } else {
                    console.error(runes.error);
                    runes = [];
                }

                inscriptions = await Wallet.request('ord_getInscriptions',
                    {
                        page_size: 60,
                        page_number: 1
                    }
                );
                if (inscriptions.status === 'success') {
                    console.log(inscriptions);
                    inscriptions = inscriptions.result;
                } else {
                    console.error(inscriptions.error);
                    inscriptions = [];
                }

            }
        }
        else if (response.status === 'error') {
            console.log(response.error.message);
            return false;
        }
        return [address, balance, inscriptions];

    } catch (err) {
        console.log(err);
    }

The only method that does not work is: ord_getInscriptions

This is the error message:

    [
    {
        "kind": "schema",
        "type": "number",
        "expected": "number",
        "received": "undefined",
        "message": "Invalid type: Expected number but received undefined",
        "path": [
            {
                "type": "object",
                "origin": "value",
                "input": {
                    "jsonrpc": "2.0",
                    "method": "ord_getInscriptions",
                    "params": {
                        "page_size": 60,
                        "page_number": 1
                    },
                    "id": "dp9hicH0wWqvQt_JhQB_r"
                },
                "key": "params",
                "value": {
                    "page_size": 60,
                    "page_number": 1
                }
            },
            {
                "type": "object",
                "origin": "value",
                "input": {
                    "page_size": 60,
                    "page_number": 1
                },
                "key": "offset"
            }
        ]
    },
    {
        "kind": "schema",
        "type": "number",
        "expected": "number",
        "received": "undefined",
        "message": "Invalid type: Expected number but received undefined",
        "path": [
            {
                "type": "object",
                "origin": "value",
                "input": {
                    "jsonrpc": "2.0",
                    "method": "ord_getInscriptions",
                    "params": {
                        "page_size": 60,
                        "page_number": 1
                    },
                    "id": "dp9hicH0wWqvQt_JhQB_r"
                },
                "key": "params",
                "value": {
                    "page_size": 60,
                    "page_number": 1
                }
            },
            {
                "type": "object",
                "origin": "value",
                "input": {
                    "page_size": 60,
                    "page_number": 1
                },
                "key": "limit"
            }
        ]
    }
]

Thanks for your help

aryzing commented 1 week ago

Thanks for reporting @danilomarcus. Not sure if this is the same or a different error for the same method. Seems the issue is with the offset property that has been marked as required yet not supplied with the request made to the wallet. Will confirm whether it should be required or not and make the necessary fixes

aryzing commented 1 week ago

@danilomarcus seems the issue with the code you shared is here,

                inscriptions = await Wallet.request('ord_getInscriptions',
                    {
                        page_size: 60,
                        page_number: 1
                    }
                );

The expected arguments are limit and offset, and not the page* ones used above.

Are you using Typescript? There should be a type error on this line when attempting to use these unknown params. Let me know if you are using TS but not getting any type errors.

danilomarcus commented 1 week ago

limit and offset

It worked with this parameters: limit and offset

I was following this docs: https://docs.xverse.app/sats-connect/bitcoin-methods/ord_getinscriptions

But it does not mention this required options, or at least I didn't saw it

Thank you very much.