Git Product home page Git Product logo

Comments (7)

yihau avatar yihau commented on August 20, 2024 1

I've check your fee payer's balance, it shows 0.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/portto/solana-go-sdk/client"
	"github.com/portto/solana-go-sdk/client/rpc"
	"github.com/portto/solana-go-sdk/common"
	"github.com/portto/solana-go-sdk/types"
)

var feePayer = types.AccountFromPrivateKeyBytes([]byte{171, 198, 211, 210, 224, 159, 123, 194, 109, 67, 84, 90, 248, 134, 20, 25, 32, 185, 1, 216, 114, 253, 61, 71, 211, 88, 58, 242, 27, 146, 27, 137, 19, 110, 184, 252, 165, 125, 39, 128, 238, 132, 66, 123, 192, 136, 48, 33, 92, 107, 3, 44, 179, 4, 191, 172, 226, 212, 98, 118, 113, 163, 233, 105})

var alice = types.AccountFromPrivateKeyBytes([]byte{171, 198, 211, 210, 224, 159, 123, 194, 109, 67, 84, 90, 248, 134, 20, 25, 32, 185, 1, 216, 114, 253, 61, 71, 211, 88, 58, 242, 27, 146, 27, 137, 19, 110, 184, 252, 165, 125, 39, 128, 238, 132, 66, 123, 192, 136, 48, 33, 92, 107, 3, 44, 179, 4, 191, 172, 226, 212, 98, 118, 113, 163, 233, 105})

var mintPubkey = common.PublicKeyFromString("2JrfrWiKQTQKiRh6pUv8YogGwxpZcHNJTVW6E9JdFx5v")

func main() {
	c := client.NewClient(rpc.DevnetRPCEndpoint)
	feePayerBalance, err := c.GetBalance(context.Background(), feePayer.PublicKey.ToBase58())
	if err != nil {
		log.Fatalf("failed to get balance, err: %v", err)
	}
	fmt.Printf("%v, balance: %v\n", feePayer.PublicKey.ToBase58(), feePayerBalance)
}

also I've check your mint. your mint hasn't initialized either.

https://explorer.solana.com/address/2JrfrWiKQTQKiRh6pUv8YogGwxpZcHNJTVW6E9JdFx5v?cluster=devnet

I guess in previous example I used http://localhost:8899 as endpoint
in this example I forgot to change it. It used devnet endpoint.
so I think you can do

- c := client.NewClient(rpc.DevnetRPCEndpoint)
+ c := client.NewClient("http://localhost:8899")

and it will work

from solana-go-sdk.

kvakhil95 avatar kvakhil95 commented on August 20, 2024 1

Thanks. Understood the issue.

from solana-go-sdk.

yihau avatar yihau commented on August 20, 2024 1

It is my fault, I forgot to change all example to use the same endpoint.
I've modified it. Thank for your issue!

from solana-go-sdk.

yihau avatar yihau commented on August 20, 2024

I guess your fee payer(funder) don't have enough balance to create token account.
It will cost you 0.00203928 SOL for a token account.
also remember check your connection is the same

from solana-go-sdk.

kvakhil95 avatar kvakhil95 commented on August 20, 2024

Just cross-checked. My fee payer has 7.998528400 SOL balance.
And the connection is the same too.

from solana-go-sdk.

yihau avatar yihau commented on August 20, 2024

would you share your code to me?
not sure how you pass these accounts into instruction.

from solana-go-sdk.

kvakhil95 avatar kvakhil95 commented on August 20, 2024

This is my code. It is taken from the documents you've created.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/portto/solana-go-sdk/client"
	"github.com/portto/solana-go-sdk/client/rpc"
	"github.com/portto/solana-go-sdk/common"
	"github.com/portto/solana-go-sdk/program/assotokenprog"
	"github.com/portto/solana-go-sdk/types"
)

var feePayer = types.AccountFromPrivateKeyBytes([]byte{171, 198, 211, 210, 224, 159, 123, 194, 109, 67, 84, 90, 248, 134, 20, 25, 32, 185, 1, 216, 114, 253, 61, 71, 211, 88, 58, 242, 27, 146, 27, 137, 19, 110, 184, 252, 165, 125, 39, 128, 238, 132, 66, 123, 192, 136, 48, 33, 92, 107, 3, 44, 179, 4, 191, 172, 226, 212, 98, 118, 113, 163, 233, 105})

var alice = types.AccountFromPrivateKeyBytes([]byte{171, 198, 211, 210, 224, 159, 123, 194, 109, 67, 84, 90, 248, 134, 20, 25, 32, 185, 1, 216, 114, 253, 61, 71, 211, 88, 58, 242, 27, 146, 27, 137, 19, 110, 184, 252, 165, 125, 39, 128, 238, 132, 66, 123, 192, 136, 48, 33, 92, 107, 3, 44, 179, 4, 191, 172, 226, 212, 98, 118, 113, 163, 233, 105})

var mintPubkey = common.PublicKeyFromString("2JrfrWiKQTQKiRh6pUv8YogGwxpZcHNJTVW6E9JdFx5v")

func main() {
	c := client.NewClient(rpc.DevnetRPCEndpoint)

	ata, _, err := common.FindAssociatedTokenAddress(alice.PublicKey, mintPubkey)
	if err != nil {
		log.Fatalf("find ata error, err: %v", err)
	}
	fmt.Println("ata:", ata.ToBase58())

	res, err := c.GetRecentBlockhash(context.Background())
	if err != nil {
		log.Fatalf("get recent block hash error, err: %v\n", err)
	}
	rawTx, err := types.CreateRawTransaction(types.CreateRawTransactionParam{
		Instructions: []types.Instruction{
			assotokenprog.CreateAssociatedTokenAccount(
				feePayer.PublicKey,
				alice.PublicKey,
				mintPubkey,
			),
		},
		Signers:         []types.Account{feePayer},
		FeePayer:        feePayer.PublicKey,
		RecentBlockHash: res.Blockhash,
	})
	if err != nil {
		log.Fatalf("generate tx error, err: %v\n", err)
	}

	txhash, err := c.SendRawTransaction(context.Background(), rawTx)
	if err != nil {
		log.Fatalf("send raw tx error, err: %v\n", err)
	}

	log.Println("txhash:", txhash)
}

I am able to generate the ATA following which I get the error.

ata: HXjpqhEnEMUC2AWTEs4uampaMPVPgKoFqDNR78GLcBQa
2021/10/04 15:36:03 send raw tx error, err: rpc response error: {"code":-32002,"message":"Transaction simulation failed: Attempt to debit an account but found no record of a prior credit.","data":{"accounts":null,"err":"AccountNotFound","logs":[]}}
exit status 1

This was my exact error.

from solana-go-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.