Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get large token holders with getProgramAccounts? #258

Open
BillInUK opened this issue Nov 10, 2024 · 2 comments
Open

how to get large token holders with getProgramAccounts? #258

BillInUK opened this issue Nov 10, 2024 · 2 comments

Comments

@BillInUK
Copy link

i am try to get large token holders of USDT.so i try it with the following code:

// Copyright 2021 github.com/gagliardetto
// This file has been modified by github.com/gagliardetto
//
// Copyright 2020 dfuse Platform Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rpc

import (
	"context"

	"github.com/gagliardetto/solana-go"
)

// GetProgramAccounts returns all accounts owned by the provided program publicKey.
func (cl *Client) GetProgramAccounts(
	ctx context.Context,
	publicKey solana.PublicKey,
) (out GetProgramAccountsResult, err error) {
	return cl.GetProgramAccountsWithOpts(
		ctx,
		publicKey,
		nil,
	)
}

// GetProgramAccountsWithOpts returns all accounts owned by the provided program publicKey.
func (cl *Client) GetProgramAccountsWithOpts(
	ctx context.Context,
	publicKey solana.PublicKey,
	opts *GetProgramAccountsOpts,
) (out GetProgramAccountsResult, err error) {
	obj := M{
		"encoding": "base64",
	}
	if opts != nil {
		if opts.Commitment != "" {
			obj["commitment"] = string(opts.Commitment)
		}
		if len(opts.Filters) != 0 {
			obj["filters"] = opts.Filters
		}
		if opts.Encoding != "" {
			obj["encoding"] = opts.Encoding
		}
		if opts.DataSlice != nil {
			obj["dataSlice"] = M{
				"offset": opts.DataSlice.Offset,
				"length": opts.DataSlice.Length,
			}
		}
	}

	params := []interface{}{publicKey, obj}

	err = cl.rpcClient.CallForInto(ctx, &out, "getProgramAccounts", params)
	return
}

but it returns the following error:

panic: rpc call getProgramAccounts() on https://sly-hardworking-dew.solana-mainnet.quiknode.pro/f6eb1261fe38b21326f892aabef573a7fa01a80a/ status code: 200. could not decode body to rpc response: jsonrpc.RPCResponse.Result: net/http: request canceled (Client.Timeout or context cancellation while reading body) [recovered]
	panic: rpc call getProgramAccounts() on https://sly-hardworking-dew.solana-mainnet.quiknode.pro/f6eb1261fe38b21326f892aabef573a7fa01a80a/ status code: 200. could not decode body to rpc response: jsonrpc.RPCResponse.Result: net/http: request canceled (Client.Timeout or context cancellation while reading body)

goroutine 35 [running]:
testing.tRunner.func1.2({0x105462300, 0x140001c0180})
	/Users/mac/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/testing/testing.go:1631 +0x1c4
testing.tRunner.func1()
	/Users/mac/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/testing/testing.go:1634 +0x33c
panic({0x105462300?, 0x140001c0180?})
	/Users/mac/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/runtime/panic.go:770 +0x124
meme-pos/utils.TestGetSnapShot(0x140001ad040?)
	/Users/mac/GolandProjects/meme-pos/utils/solana_utils_test.go:37 +0x37c
testing.tRunner(0x140001ad040, 0x1054d95e0)
	/Users/mac/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/testing/testing.go:1689 +0xec
created by testing.(*T).Run in goroutine 1
	/Users/mac/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/testing/testing.go:1742 +0x318


Process finished with the exit code 1

may I retrieve a large number of token holders through multiple paginated requests?

@gagliardetto
Copy link
Owner

The tokenkeg program has hundreds of millions of accounts; gPA will fail.

You're better off using accountsDB snapshots, and some way to extract them from there.

@BillInUK
Copy link
Author

Could you please tell me what ways are available to use accountsDB? Both paid and free options are fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants