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 getTokenAccountOwner #152

Open
yangyile1990 opened this issue Aug 16, 2023 · 1 comment
Open

how to getTokenAccountOwner #152

yangyile1990 opened this issue Aug 16, 2023 · 1 comment

Comments

@yangyile1990
Copy link

yangyile1990 commented Aug 16, 2023

I see the https://solscan.io/account/7N6Y6cYRdVuD2ViCk6imDMpjsvd8L83jM2hmY7GXVVXX

address = 7N6Y6cYRdVuD2ViCk6imDMpjsvd8L83jM2hmY7GXVVXX

const publicKey = new solanaWeb3.PublicKey(address);
const tokenAccountInfo = await connection.getAccountInfo(publicKey);
const owner = tokenAccountInfo.data.parsed.info.owner;

want owner = g6C2kzzxGa653aAiHmN8HTntAAPjeSD5C191h8rdqrQ

while when i see the golang sdk.

type Account struct {
	// Number of lamports assigned to this account
	Lamports uint64 `json:"lamports"`

	// Pubkey of the program this account has been assigned to
	Owner solana.PublicKey `json:"owner"`

	// Data associated with the account, either as encoded binary data or JSON format {<program>: <state>}, depending on encoding parameter
	Data *DataBytesOrJSON `json:"data"`

	// Boolean indicating if the account contains a program (and is strictly read-only)
	Executable bool `json:"executable"`

	// The epoch at which this account will next owe rent
	RentEpoch uint64 `json:"rentEpoch"`
}

how can I get data.parsed.info.owner?

too hard to use.

@yangyile1990
Copy link
Author

yangyile1990 commented Aug 16, 2023

aha. I knew it.

toSub, erc := GetTxnInxAccount(txn, inx, 2)
			if erc != nil {
				return nil, erc
			}
			toAcc, err := s.client3.GetAccountInfoWithOpts(context.TODO(), toSub, &rpc3.GetAccountInfoOpts{
				Encoding: solana.EncodingJSONParsed,
			})
			if err != nil {
				return nil, cerror.NewError(cerror.CODE_THIRD_REQ_ERROR, "GetAccountInfo", toSub.String(), err.Error())
			}
			simJson, err := simplejson.NewJson(toAcc.Value.Data.GetRawJSON())
			if err != nil {
				return nil, cerror.NewError(cerror.CODE_NODE_RESP_ERROR, err.Error())
			}
			toOwner, err := simJson.Get("parsed").Get("info").Get("owner").String()
			if err != nil {
				return nil, cerror.NewError(cerror.CODE_UNKNOWN, err.Error())
			}

but I still think it is a little too hard to use.

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

1 participant