Comments (9)
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.
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.
- tokenprog.TransferChecked
Signer
field usually uses in multisig wallet. If you're not a multisig wallet, you can pass a empty. Signers: []types.Account{userMakingTransaction, userMakingTransaction}
why you pass two same accounts?- 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.
Hey thanks for your replies, however I have some more questions about your last answers.
-
thanks I'll give it a try
-
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?
-
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.
the same signers only need to be passed once.
from solana-go-sdk.
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.
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.
It worked !!!
Thanks heaps :)
from solana-go-sdk.
My pleasure
from solana-go-sdk.
Related Issues (20)
- how to decode the instruction.data? HOT 1
- how to getTokenAccountOwner HOT 3
- how to get the mint name of 7i5KKsX2weiTkry7jA4ZwSuXGhs5eJBEjY8vVxR4pfRx HOT 3
- How to get SOL transfers from a response getTransaction() HOT 2
- creating a new wallet and other things HOT 1
- Cant understand how to give instructions for Launchmynft.io
- Cant understand how to give instructions for raydium swap HOT 2
- How to create stake account? HOT 2
- [HELP] Deserializing AccountData data field into address lookup tables
- UpdateMetadataAccount returning deprecated error HOT 2
- Any plan to support anchor? HOT 3
- Websocket API support
- How do I initiate a USDT SPL transfer transaction? HOT 4
- Add Priority Fee to Transaction HOT 1
- How do I initiate a USDT SPL transfer transaction? HOT 3
- An optimization suggestion about transaction serialization
- Add unitsConsumed field to RPC simulateTransaction response HOT 1
- GetSlotLeader HOT 2
- Add GetSlotLeaders HOT 1
- Add GetProgramAccounts method to the client folder
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solana-go-sdk.