gagliardetto / solana-go Goto Github PK
View Code? Open in Web Editor NEWGo SDK library and RPC client for the Solana Blockchain
License: Apache License 2.0
Go SDK library and RPC client for the Solana Blockchain
License: Apache License 2.0
Reference: https://docs.solana.com/developing/clients/jsonrpc-api#blocksubscribe---unstable-disabled-by-default
The docs are a bit ambiguous on this, probably be cause the endpoint is still considered unstable. In the endpoint description, it says the first parameter is filter: <string>|<object>
, but the example indicates it should be <string>|<object>
, like { "jsonrpc": "2.0", "id": "1", "method": "blockSubscribe", "params": ["all"] }
. This library implements the first, e.g. "params": [{"filter": "all"}]
, which doesn't work.
Is there a way to know txid before transaction is sent to the rpc node?
Hello
Any example of an offline transaction with multiple signers?
https://docs.solana.com/offline-signing
JS library has this method https://github.com/solana-labs/solana-web3.js/blob/85bd523517683e1dbbb1d1e88116215dbd8a4678/src/nonce-account.ts#L55
Is there something similar in solana-go?
Is there a way that I can use this library to send tokens from one wallet to another?
If so please tell me where.
Hello,
A new connect method is needed that accepts a requestHeader http.Header
parameter that passes that to the DialContext
method.
The existing is missing it.
Line 56 in 2acfcf2
Thanks for enriching the Solana ecosystem with a Go SDK!
Simple bool argument would do justice.
Needed in some cases.
I tried many times to transfer usdt to other address, but failed.
Transferring sol was successful.
critical code
fromTokenAccount, _, _ := solana.FindAssociatedTokenAddress(s.PoolManager.PublicKey(), s.UsdtPublicKey)
g.Dump("from ", fromTokenAccount.String())
toTokenAccount, _, _ := solana.FindAssociatedTokenAddress(solana.MustPublicKeyFromBase58(toAddress), s.UsdtPublicKey)
g.Dump("to ", toTokenAccount.String())
instruction0 := system.NewTransferInstruction(
uint64(amount*s.UsdtDecimal),
fromTokenAccount,
toTokenAccount,
).Build()
tx, err := solana.NewTransaction([]solana.Instruction{instruction0}, recent.Value.Blockhash, solana.TransactionPayer(s.PoolManager.PublicKey()))
if err != nil {
return
}
_, err = tx.Sign(
func(key solana.PublicKey) *solana.PrivateKey {
if s.PoolManager.PublicKey().Equals(key) {
return &s.PoolManager
}
return nil
},
)
if err != nil {
return
}
// Pretty print the transaction:
tx.EncodeTree(text.NewTreeEncoder(os.Stdout, "Transfer USDT"))
sig, err = client.SendTransaction(ctx, tx)
if err != nil {
return
}
result
error = signer key "5m1GGanP4pqbdYECvAA6YAuhmvpbKnuzmnuu6wQ3Y3vo" not found. Ensure all the signer keys are in the vault
➜ slnc git:(main) ~/sdk/go1.16.5/bin/go run main.go serum get market HWHvQhFmJB3NUcu1aihKmrKegfVxBEHzwVX6yZCKEsi1
Error: fetch market: getting quote mint: required [1] byte, remaining [0]
Usage:
cmd serum get market {market_addr} [flags]
Flags:
-h, --help help for market
Global Flags:
-H, --http-header strings HTTP header to add to JSON-RPC requests
--kms-gcp-keypath string Path to the cryptoKeys within a keyRing on GCP
-u, --rpc-url string API endpoint of eos.io blockchain node (default "http://api.mainnet-beta.solana.com")
--vault-file string Wallet file that contains encrypted key material (default "./solana-vault.json")
fetch market: getting quote mint: required [1] byte, remaining [0]
exit status 1
HWHvQhFmJB3NUcu1aihKmrKegfVxBEHzwVX6yZCKEsi1
- its SOL/USDT
It seems that someting wrong with decoding USDT token info to token.Mint GetAccountInfo(Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB) //USDT
But its ok with some other tokens. With Cm4MmknScg7qbKqytb1mM92xgDxv3TNXos4tKbBqTDy7
RAY/SRM
market it works fine.
am i doing something wrong?
gm,
may be this is an edge case - whenever you instance many rpc.New
calls, macOS would throw tcp lookup not found
errors even after ulimit -n 69420710
or ulimit > unlimited
. so in my programs, i have to instance a global rpc.Client
via rpc.New
and then pass down to functions that require rpc interactions. this implies that many instances of rpc.New
will exceed the OS max open sockets and fail due to not being closed after usage.
so i would like to know where to start on making the pr that implements this if you dont have time to. or i would be eternally grateful if this gets implemented in a future release.
much love <3,
D
Rn, it only supports compiled InnerInstruction.
{
"parsed": {
"info": {
"amount": "1232000000",
"authority": "XLVYxeZh7mFePq74jzU2Lsd51AeJ5txYbvWDAYutVNT",
"destination": "75HgnSvXbWKZBpZHveX68ZzAhDqMzNDS29X6BGLtxMo1",
"source": "AGcGa5sVMRT3PWVtLPTh13MAaQsNMdC3PTPiaAGzdG4v"
},
"type": "transfer"
},
"program": "spl-token",
"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
}
Hi folks, I'm trying to write a client that issues CancelOrder transactions and it seems that program hasn't been implemented yet. Is that correct? If so, I'd be happy to propose a PR with it.
To clarify, the problem I'm trying to solve is that I can't create a solana.NewTransaction()
with a InstructionCancelOrder{}
because the latter doesn't fully implement solana.Instruction
. It seems that "fully" implementing CancelOrder similarly to what's done in programs/system/CreateAccount.go
for example, would solve that.
I am trying to generate code to deploy FT and mint token like I did in cli following this site(https://spl.solana.com/token)
I could easily airdrop SOL and transfer SOL to another address following README.md. But there is no spl token example.
I generated code like below. I think some of parameters are wrong. Could anyone check what I did wrongly?
func TestFT(t *testing.T) {
rpcClient := rpc.New(rpc.DevNet_RPC)
wsClient, err := ws.Connect(context.Background(), rpc.DevNet_WS)
assert.NoError(t, err)
ctx := context.TODO()
to := solana.MustPublicKeyFromBase58("9B5XszUGdMaxCZ7uSQhPzdks5ZQSmWxrmzCSvtJ6Ns6b")
fmt.Println(to)
from := solana.NewWallet()
fmt.Println(from.PublicKey())
// Airdrop 5 SOL to the new account:
out, err := rpcClient.RequestAirdrop(
ctx,
from.PublicKey(),
solana.LAMPORTS_PER_SOL*2,
rpc.CommitmentFinalized,
)
fmt.Println(out)
assert.NoError(t, err)
time.Sleep(30 * time.Second)
recent, err := rpcClient.GetRecentBlockhash(ctx, rpc.CommitmentFinalized)
assert.NoError(t, err)
FTAccount := solana.NewWallet()
createInst, err := system.NewCreateAccountInstruction(0, 100, solana.TokenProgramID, from.PublicKey(), FTAccount.PublicKey()).ValidateAndBuild()
assert.NoError(t, err)
mintInst, err := token.NewInitializeMintInstructionBuilder().
SetDecimals(9).
SetMintAuthority(from.PublicKey()).
SetMintAccount(FTAccount.PublicKey()).
SetSysVarRentPubkeyAccount(solana.SysVarRentPubkey).ValidateAndBuild()
assert.NoError(t, err)
tx, err := solana.NewTransaction(
[]solana.Instruction{
createInst,
mintInst,
},
recent.Value.Blockhash,
solana.TransactionPayer(from.PublicKey()),
)
assert.NoError(t, err)
_, err = tx.Sign(
func(key solana.PublicKey) *solana.PrivateKey {
if from.PublicKey().Equals(key) {
return &from.PrivateKey
}
if FTAccount.PublicKey().Equals(key) {
return &FTAccount.PrivateKey
}
return nil
},
)
assert.NoError(t, err)
sig, err := confirm.SendAndConfirmTransaction(
ctx,
rpcClient,
wsClient,
tx,
)
fmt.Println(sig)
assert.NoError(t, err)
}
I got this errors. I think mintInst
has wrong argument. But I do not know why it is wrong
Error Trace: solana_test.go:139
Error: Received unexpected error:
(*jsonrpc.RPCError)(0xc0008240f0)({
Code: (int) -32002,
Message: (string) (len=99) "Transaction simulation failed: Error processing Instruction 1: invalid account data for instruction",
Data: (map[string]interface {}) (len=3) {
(string) (len=8) "accounts": (interface {}) <nil>,
(string) (len=3) "err": (map[string]interface {}) (len=1) {
(string) (len=16) "InstructionError": ([]interface {}) (len=2 cap=2) {
(json.Number) (len=1) "1",
(string) (len=18) "InvalidAccountData"
}
},
(string) (len=4) "logs": ([]interface {}) (len=7 cap=8) {
(string) (len=51) "Program 11111111111111111111111111111111 invoke [1]",
(string) (len=48) "Program 11111111111111111111111111111111 success",
(string) (len=62) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]",
(string) (len=40) "Program log: Instruction: InitializeMint",
(string) (len=38) "Program log: Error: InvalidAccountData",
(string) (len=89) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1705 of 200000 compute units",
(string) (len=96) "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: invalid account data for instruction"
}
}
})
Hey,
I am trying to mirror the behaviour of a typescript lib for Solana. I need to use CreateProgramAddress
to derive a Serum Market address. To have a working example I looked through the tests cases:
I see that the resulting addresses are different and I don't really understand why. I might be missing something.
Any idea where the diff comes from? Do you by any chance have a example that work on both lib?
I don't know Rust so I also don't know if there are tests cases on the original lib.
Hi, i'm running into this issue:
$ go mod tidy
go: finding module for package github.com/gagliardetto/solana-go/text/format
github.com/johnbailon/soltest imports
github.com/gagliardetto/metaplex-go/clients/token-metadata imports
github.com/gagliardetto/solana-go/text/format: module github.com/gagliardetto/solana-go@latest found (v1.0.0), but does not contain package github.com/gagliardetto/solana-go/text/format
$ go run main.go
../../../../pkg/mod/github.com/gagliardetto/[email protected]/clients/token-metadata/ConvertMasterEditionV1ToV2.go:9:2: no required module provides package github.com/gagliardetto/solana-go/text/format; to add it:
go get github.com/gagliardetto/solana-go/text/format
$ go get github.com/gagliardetto/solana-go/text/format
go get: module github.com/gagliardetto/solana-go@upgrade found (v1.0.0), but does not contain package github.com/gagliardetto/solana-go/text/format
Hello,
I am getting the following error byte array: varlen=3069866594, missing 3069866581 bytes
when trying to read the AccountInfo of an account address. This is the account information in the dev net
Ultimately I am trying to read the account data so I can read the attributes of the NFT.
This is my code
import (
"context"
"fmt"
"github.com/gagliardetto/binary"
tokenmetadata "github.com/gagliardetto/metaplex-go/clients/token-metadata"
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
)
c := rpc.New(rpc.DevNet_RPC)
a := solana.MustPublicKeyFromBase58("Gv1VNiC7YTXb7FerKoWiB99RTXzs2Qrq6p5JpYnQ63aZ")
resp, err := c.GetAccountInfo(context.TODO(), a)
if err != nil {
panic(err)
}
d := bin.NewBorshDecoder(resp.Value.Data.GetBinary())
var meta tokenmetadata.Metadata
err = d.Decode(&meta)
if err != nil {
panic(err)
}
Any ideas what I could be doing wrong?
Is it possible to add support for the getParsedTokenAccountsByOwner call to the api?
I am attempting to pull blocks with the JSON Parsed option and repeatedly receive the following error:
2021/11/18 16:06:17 rpc.GetBlockResult.Transactions: []rpc.TransactionWithMeta: rpc.TransactionWithMeta.Transaction: solana.Transaction.Message: solana.Message.AccountKeys: []solana.PublicKey: unmarshalerDecoder: ReadString: expects " or n, but found {, error found in #1 byte of ...|{"pubkey":"|..., bigger context ...|{"pubkey":"2oz91K9pKf2sYr4oRtQvxBcxxo8gniZvXyNoMTQY|..., error found in #10 byte of ...|ble":true},{"pubkey"|..., bigger context ...|8gniZvXyNoMTQYhoqv","signer":true,"writable":true},{"pubkey":"7ycfa1ENNT5dVVoMtiMjsgVbkWKFJbu6nF2h1U|...
exit status 1
Version: github.com/gagliardetto/solana-go v1.0.2
Endpoint: rpc.MainNetBeta_RPC
Here is my code:
package main
import (
"context"
"log"
"github.com/davecgh/go-spew/spew"
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"
)
func main() {
client := rpc.New(rpc.MainNetBeta_RPC)
example, err := client.GetRecentBlockhash(context.TODO(), rpc.CommitmentFinalized)
if err != nil {
panic(err)
}
includeRewards := true
out, err := client.GetBlockWithOpts(
context.TODO(),
uint64(example.Context.Slot),
// You can specify more options here:
&rpc.GetBlockOpts{
Encoding: solana.EncodingJSONParsed,
Commitment: rpc.CommitmentFinalized,
// Get only signatures:
TransactionDetails: rpc.TransactionDetailsFull,
// Exclude rewards:
Rewards: &includeRewards,
},
)
if err != nil {
log.Fatal(err)
}
spew.Dump(out)
}
Any ideas on how to resolve this issue?
When I run this cli command to generate wasm binary:
GOOS=js GOARCH=wasm go build -o output/html/aneka_guess_number/script/app.wasm cmd/html/aneka_guess_number/app.go
I got this error:
vendor/github.com/fatih/color/color.go:21:5: undefined: isatty.IsTerminal
I tried to resolve this by bump up the version of github.com/fatih/color
, from v1.7.0
to v1.9.0
. After bumping up the version, I can compile to WASM. I create the related PR to bump up the version. #34
It's my first time creating PR to open source project, please correct me if there is mistake. Thanks!
With the json rpc api stating that getRecentBlockhash is deprecated and will no longer function on newer versions, will the solana.NewTransaction soon switch over to the updated getFeeForMessage?
Support BIP32 for Ed25519 in order to have HD wallet.
There is golang implementation of BIP32-Ed25519 and also a python implementation that can be considered to be integrated.
how to send sol from one address to another using this sdk?
Since the module github.com/dfuse-io/logging now redirects to github.com/streamingfast/logging , when I do go get -u
this error comes up:
go get: github.com/dfuse-io/[email protected] updating to
github.com/dfuse-io/[email protected]: parsing go.mod:
module declares its path as: github.com/streamingfast/logging
but was required as: github.com/dfuse-io/logging
Any reason why this hasn't been fixed? Is the old logging module different from the new one at streamingfast?
As the title suggests, How to set the timeout of RPC? Look at the source code. The default is 5 minutes.
Hello,
I don't understand if it's possible to decode a raw transaction string to a solana.Transaction object in the SDK. I'd like to do this to support the feature of getting a raw transaction from a user and only submitting that to the network via the sendTransaction rpc method, which takes a transaction.
Maybe doing some borsh decoder like here could help, but don't really know.
Any tips?
Also, if there's the interest, there could exist a function in the rpc package to submit raw transaction strings directly, without the need to convert to a transaction, or provide a function that easily converts that, maybe in the transaction package (in the case that there doesn't exist one)
Hey there,
I have asked this in another person's issue but wanted to open an official one.
When calling the TransactionFromDecoder
method the returned struct is solana.Transaction
which doesn't contain the Meta
property which when calling RPC GetTransaction
you do get.
Is there a reason for doing so and is it possible to have the Meta
property from a decoded transaction?
Thanks
I want to fetch this data from https://explorer.solana.com/address/61CCEcc5LZCp9RJ2yPhmABHno3fPLKK6Lbxrpvqdj5Bu/anchor-account?cluster=devnet
The only way I have found to make this request:
This returns me that output:
["M62xcRnxbb1i1Tdvzm+PZYfvqFyL7EY5eEUk5SclNnXPLbmZ9hPa8mLVN2/Ob49lh++oXIvsRjl4RSTlJyU2dc8tuZn2E9ryAAMAAAAAAAAABgAAADYxQ0NFYwDh9QUAAAAACgAAAE5CAAAAAAAAAAD0AQAAAAAAAAAAAQEB8AmFYgAAAAAAAQAAAGLVN2/Ob49lh++oXIvsRjl4RSTlJyU2dc8tuZn2E9ryAWQAAAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAE51bWJlciAjOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyAAAAGh0dHBzOi8vYXJ3ZWF2ZS5uZXQvd2dsbmpKQ1NweGhkNHc1NkhfWUJ0bGtGM3VhWGttU0hheDlMN3lIaWtsNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAE51bWJlciAjOQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAyAAAAGh0dHBzOi8vYXJ3ZWF2ZS5uZXQvYktSUFJPcDJ6dHoyQV9sbFJONDd1RlU2eTRmc1RQRUJzMmNFcFYtZXd1UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAP/AAAAAwEAA","base64"]
But after trying to decode this with all possible ways I understood that nothing helps, could you explain me how to solve this problem, please?
Hey there,
How would one go about:
Thanks,
Can I call the smart contract directly? How should I call it
Is it possible to interact with Serum's market using this sdk?
How do i get market params like Request queue, Event queue etc?
hi,i want use the serum package to place a order,but when i create serum.instruction,have a problem。the ide tell me the serum.instruction have not implement solana.instruction(three method ProgramID, Accounts, Data).
i want to know how to use serum.instruction to send transaction?
what is my mistake?
thank you!
rpc.New
create a new http client and keepalive sessions, but there's no Close()
method to clean them up.
currently cannot directly convert solana.hash to string using Go. It will be helpful if the conversion can be supported.
# github.com/gagliardetto/solana-go
../../go/pkg/mod/github.com/gagliardetto/[email protected]/transaction.go:260:2: undefined: bin.EncodeCompactU16Length
../../go/pkg/mod/github.com/gagliardetto/[email protected]/transaction.go:276:16: encoder.WriteBytes undefined (type *bin.Encoder has no field or method WriteBytes)
../../go/pkg/mod/github.com/gagliardetto/[email protected]/transaction.go:281:25: undefined: bin.DecodeCompactU16LengthFromByteReader
../../go/pkg/mod/github.com/gagliardetto/[email protected]/transaction.go:287:28: decoder.ReadNBytes undefined (type *bin.Decoder has no field or method ReadNBytes)
../../go/pkg/mod/github.com/gagliardetto/[email protected]/types.go:36:7: undefined: bin.EncoderDecoder
../../go/pkg/mod/github.com/gagliardetto/[email protected]/types.go:64:7: undefined: bin.EncoderDecoder
../../go/pkg/mod/github.com/gagliardetto/[email protected]/types.go:93:2: undefined: bin.EncodeCompactU16Length
../../go/pkg/mod/github.com/gagliardetto/[email protected]/types.go:100:2: undefined: bin.EncodeCompactU16Length
../../go/pkg/mod/github.com/gagliardetto/[email protected]/types.go:103:3: undefined: bin.EncodeCompactU16Length
../../go/pkg/mod/github.com/gagliardetto/[email protected]/types.go:108:3: undefined: bin.EncodeCompactU16Length
../../go/pkg/mod/github.com/gagliardetto/[email protected]/types.go:108:3: too many errors
I'm currently working on a sol back-end wallet project. I'm familiar with eth series. I know that a TX contains from, to and amount.
However, I found that there is no explicit amount field in Sol's API. Instead, it is divided into postBalances and preBalances.
so,do I need to build postbalances, prebalances and accountkeys into a data struct and calculate the amount? I count found how to parse instructions.data.
Can you give me some advice?
Hello,
sorry for the disturbance. I am currently trying to make account info readable or usable. The problem is that I can't parse the data into a struct like in CMv2, because I don't know the data structure. Do you have an idea how I can solve this problem? An account would be for example: sSQ2Nv69cmb7AD7zMF9ka8mTUSzKXgDRghNLm6Dy3m9
(mainnet)
With kind regards,
Felix
I tried to use GetAccountInfoWithOpts
, I only need to change the Commitment
option like this:
accountInfo, err := cli.rpcClient.GetAccountInfoWithOpts(
context.Background(),
accountPubKey,
&rpc.GetAccountInfoOpts{
Commitment: rpc.CommitmentConfirmed,
},
)
but getting this error:
rpc.GetAccountInfoResult.Value: rpc.Account.Executable: Data: unmarshalerDecoder: Unknown kind: [34 74 110 114 80 57 34], error found in #10 byte of ...|a":"JnrP9","executab|..., bigger context ...|{"context":{"slot":395502},"value":{"data":"JnrP9","executable":false,"lamports":918720,"owner":"7te|...
I think the error is because I did not set the Encoding
option. If I code like this, it works.
accountInfo, err := cli.rpcClient.GetAccountInfoWithOpts(
context.Background(),
accountPubKey,
&rpc.GetAccountInfoOpts{
Encoding: solana.EncodingBase64,
Commitment: rpc.CommitmentConfirmed,
},
)
I think, it's good to add something like default Encoding if the Encoding option is empty string. Something like this on GetAccountInfoWithOpts
:
if opts.Encoding == "" {
obj["encoding"] = solana.EncodingBase64
}
What do you think?
Heya. I want to get associated account from solana. Is there any implementation available on gagliardetto/solana-go?
Ask - Do you have an example of using GetProgramAccountsWithOpts that includes the dataslice and memcmp filters?
I am trying to use DataSlice and Filters with GetProgramAccountsWithOpts and I'm sure I'm making some rookie mistake here with the format but I can't figure out the proper format to include the memcmp filter. Thank you.
out, err := client.GetProgramAccountsWithOpts(
context.TODO(),
solana.MustPublicKeyFromBase58("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),
&rpc.GetProgramAccountsOpts{
Encoding: solana.EncodingBase64Zstd,
Commitment: rpc.CommitmentFinalized,
DataSlice: &rpc.DataSlice{
Offset: pointer.ToUint64(0),
Length: pointer.ToUint64(1024),
},
//TODO: what is the correct format for filters
Filters: ,
},
)
Here is the stack:
runtime.throw({0x175c318?, 0xc02ad833c0?})
/usr/lib/go-1.18/src/runtime/panic.go:992 +0x71 fp=0xc02ad83380 sp=0xc02ad83350 pc=0x449931
runtime.sigpanic()
/usr/lib/go-1.18/src/runtime/signal_unix.go:825 +0x305 fp=0xc02ad833d0 sp=0xc02ad83380 pc=0x45fbe5
aeshashbody()
/usr/lib/go-1.18/src/runtime/asm_amd64.s:1343 +0x39f fp=0xc02ad833d8 sp=0xc02ad833d0 pc=0x479cbf
runtime.mapiternext(0xc02f1e8e80)
/usr/lib/go-1.18/src/runtime/map.go:934 +0x2cb fp=0xc02ad83448 sp=0xc02ad833d8 pc=0x4233cb
runtime.mapiterinit(0xc02ad834e0?, 0x420be5?, 0xc02f1c9ea8?)
/usr/lib/go-1.18/src/runtime/map.go:861 +0x228 fp=0xc02ad83468 sp=0xc02ad83448 pc=0x4230a8
reflect.mapiterinit(0x4229bd?, 0x1536ba0?, 0xc02f1af3a8?)
/usr/lib/go-1.18/src/runtime/map.go:1373 +0x19 fp=0xc02ad83490 sp=0xc02ad83468 pc=0x476319
github.com/modern-go/reflect2.(*UnsafeMapType).UnsafeIterate(...)
/home/user/go/pkg/mod/github.com/modern-go/[email protected]/unsafe_map.go:112
github.com/json-iterator/go.(*sortKeysMapEncoder).Encode(0xc02f319020, 0xc02e443198, 0xc02f305140)
/home/user/go/pkg/mod/github.com/json-iterator/[email protected]/reflect_map.go:291 +0x225 fp=0xc02ad83600 sp=0xc02ad83490 pc=0x726cc5
github.com/json-iterator/go.(*onePtrEncoder).Encode(0xc02f301360, 0xc02f318810, 0xc02f1e8e80?)
/home/user/go/pkg/mod/github.com/json-iterator/[email protected]/reflect.go:219 +0x82 fp=0xc02ad83638 sp=0xc02ad83600 pc=0x71efc2
github.com/json-iterator/go.(*Stream).WriteVal(0xc02f305140, {0x158e020, 0xc02f318810})
/home/user/go/pkg/mod/github.com/json-iterator/[email protected]/reflect.go:98 +0x158 fp=0xc02ad836a8 sp=0xc02ad83638 pc=0x71e2d8
https://api.magiceden.dev/#auth-info-82874536-9430-4dae-81dc-1235baaa3ef3
in /instructions/buy it returns data that's array of integer. In their docs it will be converted into buffer and consumed by message decoder.
When I try to do that in golang it doesn't work and failed to decode the data
Golang code:
data := responseTx.Tx.Data
buf := make([]byte, len(data))
for i, d := data {
buf[i] = byte(d)
}
tx, err := solana.TransactionFromDecoder(bin.NewBinDecoder(buf))
Input:
data = [1,0,9,20,225,137,187,132,187,32,147,173,43,163,223,65,131,162,193,42,192,159,17,212,162,207,219,137,175,244,246,208,43,32,154,238,143,142,48,46,229,90,171,138,102,8,144,82,192,134,88,49,12,189,138,222,113,61,218,218,181,24,242,189,61,99,136,65,196,242,164,172,136,81,180,154,105,86,217,232,114,177,80,218,126,68,36,219,232,7,97,66,21,150,26,150,175,68,196,177,102,193,1,248,66,21,84,90,171,143,66,175,82,152,249,58,137,57,190,200,137,220,64,181,8,198,51,6,96,38,138,225,255,21,35,174,141,211,83,149,162,153,19,218,231,60,186,70,34,169,74,45,147,70,248,106,120,29,192,83,198,44,4,174,6,65,215,207,111,121,182,215,225,243,94,74,34,197,254,6,58,219,44,150,187,27,196,166,160,240,71,217,227,180,139,14,12,158,58,228,224,183,152,74,250,18,157,96,7,160,158,224,142,150,46,161,202,218,73,218,230,18,50,147,194,191,195,125,8,175,246,228,16,89,36,102,175,155,72,107,229,118,121,242,246,139,65,205,220,49,224,32,146,119,74,143,99,98,237,19,100,86,96,93,8,145,61,224,5,62,188,181,150,48,71,56,229,110,39,39,82,37,99,189,75,58,132,117,251,109,190,41,110,63,77,30,236,241,173,15,85,172,25,39,211,100,236,45,65,196,249,149,133,127,65,57,58,215,199,190,66,39,49,131,147,224,252,92,124,240,210,8,192,184,182,228,87,89,35,144,23,73,35,197,120,36,50,169,143,71,179,207,36,212,146,159,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,195,27,24,204,62,20,138,10,82,147,129,137,32,237,250,237,171,57,30,73,51,108,11,116,219,102,157,16,71,3,66,75,145,66,174,215,146,153,82,142,79,92,42,195,58,12,218,147,137,182,146,105,58,9,209,230,235,134,206,164,17,28,156,212,246,133,86,151,50,106,40,222,250,246,5,67,6,18,251,213,239,142,84,131,191,154,252,251,23,226,204,42,247,89,214,15,6,221,246,225,215,101,161,147,217,203,225,70,206,235,121,172,28,180,133,237,95,91,55,145,58,140,245,133,126,255,0,169,6,167,213,23,25,44,92,81,33,140,201,76,61,74,241,127,88,218,238,8,155,161,253,68,227,219,217,138,0,0,0,0,140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89,0,11,227,225,235,161,122,71,63,137,176,247,232,226,73,64,242,10,235,142,188,167,26,136,253,233,93,75,131,183,26,9,5,33,159,137,154,129,212,255,132,251,89,61,46,223,138,144,172,27,58,179,66,88,247,223,35,62,165,3,2,177,189,46,223,64,67,143,181,25,82,110,138,69,12,221,5,93,218,23,254,247,227,114,53,49,75,129,202,98,7,63,109,177,26,78,3,19,6,0,11,1,7,12,11,17,242,35,198,137,82,225,242,182,254,128,40,4,156,77,0,0,0,19,12,0,11,13,14,1,7,12,2,7,15,11,16,34,102,6,61,18,1,218,235,234,255,254,128,40,4,156,77,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19,22,0,3,11,4,13,14,1,5,7,12,6,2,7,8,7,15,11,17,18,16,9,10,42,37,74,217,157,79,49,35,6,254,250,128,40,4,156,77,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255]
Error Exception:
panic: required [1] byte, remaining [0]
goroutine 1 [running]:
main.buy_listing({{0x1411560, 0xc000078700}, 0x0, {0x0, 0x0}, 0x0}, {0x139be6b?, 0x100e387?}, {0x0, 0x0}, ...)
cannot override it in userspace as Client::logsSubscribe is private
In the EncodeToTree
of the associatedtokenaccount
it will try to access the sysVarRent (index 6) of the create ATA instruction.
This sysVarRent
account is not required by the createATA instructions itself.
Reference:
https://github.com/gagliardetto/solana-go/blob/main/programs/associated-token-account/Create.go#L179
I am trying to replicate this solana example hello world program in .ts using go. But I am stuck on using system.NewCreateAccountWithSeedInstruction
. I got this error Transaction simulation failed: Error processing Instruction 0: invalid instruction data
when executing confirm.SendAndConfirmTransaction
using system.NewCreateAccountWithSeedInstruction
instruction:
2021/12/24 11:57:11 (*jsonrpc.RPCError)(0xc0001f5890)({
Code: (int) -32002,
Message: (string) (len=87) "Transaction simulation failed: Error processing Instruction 0: invalid instruction data",
Data: (map[string]interface {}) (len=3) {
(string) (len=8) "accounts": (interface {}) <nil>,
(string) (len=3) "err": (map[string]interface {}) (len=1) {
(string) (len=16) "InstructionError": ([]interface {}) (len=2 cap=2) {
(json.Number) (len=1) "0",
(string) (len=22) "InvalidInstructionData"
}
},
(string) (len=4) "logs": ([]interface {}) (len=2 cap=2) {
(string) (len=51) "Program 11111111111111111111111111111111 invoke [1]",
(string) (len=73) "Program 11111111111111111111111111111111 failed: invalid instruction data"
}
}
})
And here is my code in go:
func main() {
// var
ctx := context.Background()
rpcCli := rpc.New(rpc.LocalNet_RPC)
wsCli, _ := ws.Connect(ctx, rpc.LocalNet_WS)
payerPrivateKey, _ := solana.PrivateKeyFromBase58("5LRLfrUP22VtiNaPGAEgHPucoJmG8ejmomMVmpn4fkXjexYsT7RQGfGuMePG5PKvecZxMGrqa6EP2RmYcm7TYQvX") // don't worry, I only use this private key in my local computer
payerAccount, _ := solana.WalletFromPrivateKeyBase58(payerPrivateKey.String())
programID := "4sCcZNQR8vfWckyi5L9KdptdaiLxdiMjVgKQay7HxzmK"
programPubKey, _ := solana.PublicKeyFromBase58(programID)
// create new subaccount (seed account)
newSubAccount, err := solana.CreateWithSeed(
payerAccount.PublicKey(),
"hello",
programPubKey,
)
if err != nil {
log.Fatalln("Failed to CreateWithSeed")
}
instruction, err := system.NewCreateAccountWithSeedInstruction(
payerAccount.PublicKey(),
"hello",
918720,
4,
programPubKey,
payerAccount.PublicKey(),
newSubAccount,
payerAccount.PublicKey(),
).ValidateAndBuild()
if err != nil {
log.Fatalln("Failed building NewCreateAccountInstruction instruction", err)
}
instructionData, _ := instruction.Data()
fmt.Printf("------> instructionData length: %d bytes, data: %v\n", len(instructionData), instructionData)
instructions := []solana.Instruction{instruction}
signers := []solana.PrivateKey{payerAccount.PrivateKey}
opts := []solana.TransactionOption{solana.TransactionPayer(payerAccount.PublicKey())}
// create recent blockhash
recent, err := rpcCli.GetRecentBlockhash(ctx, rpc.CommitmentFinalized)
if err != nil {
log.Fatalln(err)
}
// create transaction
tx, err := solana.NewTransaction(
instructions,
recent.Value.Blockhash,
opts...,
)
if err != nil {
log.Fatalln(err)
}
// sign transaction
_, err = tx.Sign(
func(key solana.PublicKey) *solana.PrivateKey {
for _, signer := range signers {
if signer.PublicKey().Equals(key) {
return &signer
}
}
return nil
},
)
if err != nil {
log.Fatalln(err)
}
tx.EncodeTree(text.NewTreeEncoder(os.Stdout, "Transfer SOL"))
// send and confirm transaction
_, err = confirm.SendAndConfirmTransaction(
ctx,
rpcCli,
wsCli,
tx,
)
if err != nil {
log.Fatalln(err)
}
}
I tried to print the instruction.Data()
in go and got this
------> instructionData length: 90 bytes, data: [3 0 0 0 204 95 77 127 148 25 135 127 89 146 22 90 233 80 113 3 70 176 165 222 81 200 100 223 117 165 155 44 53 225 124 20 5 104 101 108 108 111 192 4 14 0 0 0 0 0 4 0 0 0 0 0 0 0 57 111 59 111 183 248 249 251 128 174 206 0 81 22 3 173 244 104 15 249 239 112 33 255 66 169 29 66 7 106 231 230]
And here is the instruction data on the .ts from the solana helloworld example for comparison
console.log(instruction.data.buffer)
ArrayBuffer {
[Uint8Contents]: <03 00 00 00 cc 5f 4d 7f 94 19 87 7f 59 92 16 5a e9 50 71 03 46 b0 a5 de 51 c8 64 df 75 a5 9b 2c 35 e1 7c 14 05 00 00 00 00 00 00 00 68 65 6c 6c 6f c0 04 0e 00 00 00 00 00 04 00 00 00 00 00 00 00 39 6f 3b 6f b7 f8 f9 fb 80 ae ce 00 51 16 03 ad f4 68 0f f9 ef 70 21 ff 42 a9 1d 42 07 6a e7 e6>,
byteLength: 97
}
And here is the conversion from hex to 0-255
3 0 0 0 204 95 77 127 148 25 135 127 89 146 22 90 233 80 113 3 70 176 165 222 81 200 100 223 117 165 155 44 53 225 124 20 5 **0 0 0 0 0 0 0** 104 101 108 108 111 192 4 14 0 0 0 0 0 4 0 0 0 0 0 0 0 57 111 59 111 183 248 249 251 128 174 206 0 81 22 3 173 244 104 15 249 239 112 33 255 66 169 29 66 7 106 231 230
I see that there are 7 bytes difference (the one that I bold) in 0 0 0 0 0 0 0
. What do I do wrong? Am I missing something? Is there any example on how to use this instruction? Thanks!
If a non-compliant RPC server returns result: null
for getAccountInfo(), the client will panic with null pointer deref (line 127 on out.Value
because out
is nil
).
solana-go/rpc/getAccountInfo.go
Lines 123 to 127 in dd0af95
Ideally the RPC client would never panic under any circumstances
I have *Transaction how to convert it to base64TX
Can I create it only once and reuse it?
client := rpc.New("https://api.devnet.solana.com")
resp, err := client.GetAccountInfoWithOpts(.....)
resp2, err := client.SendTransaction(.....)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.