Git Product home page Git Product logo

Comments (9)

yihau avatar yihau commented on August 20, 2024

Technically, Devnet is a real blockchain. It is not a local cluster. If you would like to send some "real transaction", I think you can just change the endpoint to Mainnet.

from solana-go-sdk.

scottywm avatar scottywm commented on August 20, 2024
Hey, I'm having difficulty getting the transaction to work and this is the error that I get;
    rpc response error: {"code":-32003,"message":"Transaction signature verification failure"}

    Please tell me what I'm doing wrong, I would appreciate it very much.
    
  
   // first I get the private and public keys from my API 
    public_key := user.MainWallet
private_key := data.PrivateKey

    // when I print the private and public keys they are correct
fmt.Println(public_key)
fmt.Println(private_key)

var userMakingTransaction, errAcc = types.AccountFromBase58(private_key)
if errAcc != nil {
	fmt.Println(errAcc, "      line 52")
}

var mintPubkey = common.PublicKeyFromString("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB")
var from = common.PublicKeyFromString(public_key)
var privateKey = common.PublicKeyFromString(private_key)
var to = common.PublicKeyFromString("Gu1Lo6Ncb31hoRxPXjb98C7fLc3ubcYHUZ2yFBZGYiJ3")

c := client.NewClient(rpc.MainnetRPCEndpoint)

res, errNew := c.GetLatestBlockhash(context.Background())
if errNew != nil {
	log.Fatalf("get recent block hash error, err: %v\n", err)
}

fmt.Println(res.Blockhash)

tx, errTran := types.NewTransaction(types.NewTransactionParam{
	Message: types.NewMessage(types.NewMessageParam{
		FeePayer:        userMakingTransaction.PublicKey,
		RecentBlockhash: res.Blockhash,
		Instructions: []types.Instruction{
			tokenprog.TransferChecked(tokenprog.TransferCheckedParam{
				From:     from,
				To:       to,
				Mint:     mintPubkey,
				Auth:     userMakingTransaction.PublicKey,
				Signers:  []common.PublicKey{privateKey},
				Amount:   1,
				Decimals: 6,
			}),
		},
	}),
	Signers: []types.Account{userMakingTransaction, userMakingTransaction},
})

if errTran != nil {
	log.Fatalf("failed to new tx, err: %v", errTran)
}

txhash, errSend := c.SendTransaction(context.Background(), tx)

if errSend != nil {
	fmt.Println("       ", errSend)
	return
}

log.Println("txhash:", txhash)

from solana-go-sdk.

yihau avatar yihau commented on August 20, 2024
  1. tokenprog.TransferChecked Signer field usually uses in multisig wallet. If you're not a multisig wallet, you can pass a empty.
  2. Signers: []types.Account{userMakingTransaction, userMakingTransaction} why you pass two same accounts?
  3. seems you're transferring USDT but your receiver, Gu1Lo6Ncb31hoRxPXjb98C7fLc3ubcYHUZ2yFBZGYiJ3 is not a token account. if you don't familiar with solana account concept, please go through the tour here https://portto.github.io/solana-go-sdk/

from solana-go-sdk.

scottywm avatar scottywm commented on August 20, 2024

Hey thanks for your replies, however I have some more questions about your last answers.

  1. thanks I'll give it a try

  2. the reason why I pass two same accounts is because the fee is to be deducted from the account doing the transfer. Doesn't this require two accounts, first is the payer account that is to pay for the transaction fee and the second the account is the one sending the tokens?

  3. I have added USDT to that account and I have sent USDT to it and it currently has a USDT balance so I don't understand what you mean when you say that the account is not a token account. This account Gu1Lo6Ncb31hoRxPXjb98C7fLc3ubcYHUZ2yFBZGYiJ3 is the actual Solana address, its not the actual USDT address.

from solana-go-sdk.

yihau avatar yihau commented on August 20, 2024

the same signers only need to be passed once.

from solana-go-sdk.

scottywm avatar scottywm commented on August 20, 2024

OK I still cant get it to work lol.

This is what my code looks like up to this point having made the changes you recommended and it still doesn't work.
The accounts don't require more than one person to sign a transaction and you mentioned earlier that the account "Gu1Lo6Ncb31hoRxPXjb98C7fLc3ubcYHUZ2yFBZGYiJ3", is not a token account.

I am currently holding some USDT in this address and have sent USDT tokens to it before without any problems.

What am i doing wrong?

public_key := user.MainWallet
private_key := data.PrivateKey

fmt.Println(public_key)
fmt.Println(private_key)

var userMakingTransaction, errAcc = types.AccountFromBase58(private_key)
if errAcc != nil {
	fmt.Println(errAcc, "      line 52")
}

var mintPubkey = common.PublicKeyFromString("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB")
var from = common.PublicKeyFromString(public_key)
//var privateKey = common.PublicKeyFromString(private_key)
//var to = common.PublicKeyFromString("8s5W5w6JUxTLLVpcEenNbHXAm2REUDgP6vz58F12EAPQ")
var to = common.PublicKeyFromString("Gu1Lo6Ncb31hoRxPXjb98C7fLc3ubcYHUZ2yFBZGYiJ3")

c := client.NewClient(rpc.MainnetRPCEndpoint)

res, errNew := c.GetLatestBlockhash(context.Background())
if errNew != nil {
	log.Fatalf("get recent block hash error, err: %v\n", err)
}

fmt.Println(res.Blockhash)

tx, errTran := types.NewTransaction(types.NewTransactionParam{
	Message: types.NewMessage(types.NewMessageParam{
		FeePayer:        userMakingTransaction.PublicKey,
		RecentBlockhash: res.Blockhash,
		Instructions: []types.Instruction{
			tokenprog.TransferChecked(tokenprog.TransferCheckedParam{
				From:     from,
				To:       to,
				Mint:     mintPubkey,
				Auth:     userMakingTransaction.PublicKey,
				Signers:  []common.PublicKey{},
				Amount:   1,
				Decimals: 6,
			}),
		},
	}),
	Signers: []types.Account{userMakingTransaction},
})

if errTran != nil {
	log.Fatalf("failed to new tx, err: %v", errTran)
}

txhash, errSend := c.SendTransaction(context.Background(), tx)

if errSend != nil {

	fmt.Println("       ", errSend)
	return
	//log.Fatalf("send raw tx error, err: %v\n", errSend)
}

log.Println("txhash:", txhash)

from solana-go-sdk.

yihau avatar yihau commented on August 20, 2024

As a valid token transfer instruction, both of your From and To should be token accounts.

you can take a look here https://explorer.solana.com/address/Gu1Lo6Ncb31hoRxPXjb98C7fLc3ubcYHUZ2yFBZGYiJ3/tokens?display=detail

you will find an another account, 8s5W5w6JUxTLLVpcEenNbHXAm2REUDgP6vz58F12EAPQ.
it is Gu1Lo6Ncb31hoRxPXjb98C7fLc3ubcYHUZ2yFBZGYiJ3's USDT token account so in your code, your To should be the address 8s5W....

I can't see what's your From in your code but the idea is the same. You should use a USDT token account.

from solana-go-sdk.

scottywm avatar scottywm commented on August 20, 2024

It worked !!!

Thanks heaps :)

from solana-go-sdk.

yihau avatar yihau commented on August 20, 2024

My pleasure

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.