Closed rahulanand20 closed 2 years ago
how did you compose your transaction? could you paste your code here? (don't share any private key in your code snippet)
tokenprog.Transfer(tokenprog.TransferParam{
From: owner.PublicKey,
To: ata,
Auth: feePayer.PublicKey,
Amount: 1,
}),
From
instead of a SOL address.TransferChecked
. https://portto.github.io/solana-go-sdk/tour/token-transfer.htmlI tried to execute the example with taking this as a reference nft (https://explorer.solana.com/address/Br5YJoiv63AdvzNM9YRb2onGdr7sSgi2a8zJyPz3R9ii?cluster=devnet)
My error:- 2022/06/20 22:57:44 send raw tx error, err: rpc response error: {"code":-32002,"message":"Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction","data":{"accounts":null,"err":{"InstructionError":[0,"InvalidAccountData"]},"logs":["Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]","Program log: Instruction: TransferChecked","Program log: Error: InvalidAccountData","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1869 of 200000 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: invalid account data for instruction"],"unitsConsumed":0}} exit status 1
My Modified code package main
import ( "context" "log"
"github.com/portto/solana-go-sdk/client"
"github.com/portto/solana-go-sdk/common"
"github.com/portto/solana-go-sdk/program/tokenprog"
"github.com/portto/solana-go-sdk/rpc"
"github.com/portto/solana-go-sdk/types"
)
// 7s6Ro1mBBmmKmP2QDT2zzuCMqS6AVCgBQi1mRnsjX4QG var feePayer, _ = types.AccountFromBase58("")
// 43xqaQkf8N95Af64ZqafbcQsPWdKqy5BRWxH7FFYomqX var alice, _ = types.AccountFromBase58("")
var mintPubkey = common.PublicKeyFromString("7FiJvym5YqWayshU2ngN9zw7J91DKko2hkXmgrajuMA3")
var aliceTokenRandomTokenPubkey = types.NewAccount()
var aliceTokenATAPubkey = types.NewAccount()
func main() { c := client.NewClient(rpc.DevnetRPCEndpoint)
res, err := c.GetLatestBlockhash(context.Background())
if err != nil {
log.Fatalf("get recent block hash error, err: %v\n", err)
}
tx, err := types.NewTransaction(types.NewTransactionParam{
Message: types.NewMessage(types.NewMessageParam{
FeePayer: feePayer.PublicKey,
RecentBlockhash: res.Blockhash,
Instructions: []types.Instruction{
tokenprog.TransferChecked(tokenprog.TransferCheckedParam{
From: aliceTokenRandomTokenPubkey.PublicKey,
To: aliceTokenATAPubkey.PublicKey,
Mint: mintPubkey,
Auth: alice.PublicKey,
Signers: []common.PublicKey{},
Amount: 1e8,
Decimals: 8,
}),
},
}),
Signers: []types.Account{feePayer, alice},
})
if err != nil {
log.Fatalf("failed to new tx, err: %v", err)
}
txhash, err := c.SendTransaction(context.Background(), tx)
if err != nil {
log.Fatalf("send raw tx error, err: %v\n", err)
}
log.Println("txhash:", txhash)
}
you should go through token account concept first. here give you some keypoints:
if you would like to transfer the NFT you memtioned
you need to create a token account as a receiver. (https://portto.github.io/solana-go-sdk/tour/create-token-account.html) a token account transfer operation is from a token account to another token account
if you're transferring a NFT, usually Amount is 1 and Decimals is 0
Thanks, I tried to implement the code as you guided me but there is an error
I have consider this example for transfer from
Token Account
Address
DEdpuTdsSk5uBkALtiCZjLBzFUozpJ6nAdh8Vi937ppb
Mint
Af415cxd67Jo4eQNzB2c7Zr5oCP9jBX4UJdt4XCW8vbf
Owner
7s6Ro1mBBmmKmP2QDT2zzuCMqS6AVCgBQi1mRnsjX4QG
To 43xqaQkf8N95Af64ZqafbcQsPWdKqy5BRWxH7FFYomqX
My code
//43xqaQkf8N95Af64ZqafbcQsPWdKqy5BRWxH7FFYomqX var feePayer, _ = types.AccountFromBase58("")
// 7s6Ro1mBBmmKmP2QDT2zzuCMqS6AVCgBQi1mRnsjX4QG var alice, _ = types.AccountFromBase58("")
//token address var mint = common.PublicKeyFromString("Af415cxd67Jo4eQNzB2c7Zr5oCP9jBX4UJdt4XCW8vbf")
//From Token Account Address
var aliceTokenRandomTokenPubkey = common.PublicKeyFromString("DEdpuTdsSk5uBkALtiCZjLBzFUozpJ6nAdh8Vi937ppb")
//var aliceTokenATAPubkey = common.PublicKeyFromString("43xqaQkf8N95Af64ZqafbcQsPWdKqy5BRWxH7FFYomqX")
func main() { c := client.NewClient(rpc.DevnetRPCEndpoint) log.Println("feePayer", feePayer.PublicKey) log.Println("alice", alice.PublicKey) log.Println("mintPubkey", mint) log.Println("aliceTokenRandomTokenPubkey", aliceTokenRandomTokenPubkey)
//mint := types.NewAccount()
fmt.Printf("NFT: %v\n", mint)
collection := types.NewAccount()
fmt.Println(base58.Encode(collection.PrivateKey))
fmt.Printf("collection: %v\n", collection.PublicKey.ToBase58())
ata, _, err := common.FindAssociatedTokenAddress(feePayer.PublicKey, mint)
if err != nil {
log.Fatalf("failed to find a valid ata, err: %v", err)
}
tokenMetadataPubkey, err := tokenmeta.GetTokenMetaPubkey(mint)
fmt.Println("tokenMetadataPubkey", tokenMetadataPubkey.ToBase58())
if err != nil {
log.Fatalf("failed to find a valid token metadata, err: %v", err)
}
tokenMasterEditionPubkey, err := tokenmeta.GetMasterEdition(mint)
fmt.Println("tokenMasterEditionPubkey", tokenMasterEditionPubkey.ToBase58())
if err != nil {
log.Fatalf("failed to find a valid master edition, err: %v", err)
}
mintAccountRent, err := c.GetMinimumBalanceForRentExemption(context.Background(), tokenprog.MintAccountSize)
if err != nil {
log.Fatalf("failed to get mint account rent, err: %v", err)
}
res, err := c.GetLatestBlockhash(context.Background())
if err != nil {
log.Fatalf("get recent block hash error, err: %v\n", err)
}
tx, err := types.NewTransaction(types.NewTransactionParam{
Message: types.NewMessage(types.NewMessageParam{
FeePayer: feePayer.PublicKey,
RecentBlockhash: res.Blockhash,
Instructions: []types.Instruction{
sysprog.CreateAccount(sysprog.CreateAccountParam{
From: feePayer.PublicKey,
New: mint,
Owner: common.TokenProgramID,
Lamports: mintAccountRent,
Space: tokenprog.MintAccountSize,
}),
tokenmeta.CreateMetadataAccountV2(tokenmeta.CreateMetadataAccountV2Param{
Metadata: tokenMetadataPubkey,
Mint: mint,
MintAuthority: feePayer.PublicKey,
Payer: feePayer.PublicKey,
UpdateAuthority: feePayer.PublicKey,
UpdateAuthorityIsSigner: true,
IsMutable: true,
Data: tokenmeta.DataV2{
Name: "Fake SMS #1357",
Symbol: "FSMB",
Uri: "https://bafybeibd6achyemgiqqz7ur54dm7eyslgugw5yuaop7pctb44dr5htlo3i.ipfs.infura-ipfs.io",
SellerFeeBasisPoints: 100,
Creators: &[]tokenmeta.Creator{
{
Address: feePayer.PublicKey,
Verified: true,
Share: 100,
},
},
Collection: &tokenmeta.Collection{
Verified: false,
Key: collection.PublicKey,
},
Uses: &tokenmeta.Uses{
UseMethod: tokenmeta.Burn,
Remaining: 10,
Total: 10,
},
},
}),
assotokenprog.CreateAssociatedTokenAccount(assotokenprog.CreateAssociatedTokenAccountParam{
Funder: feePayer.PublicKey,
Owner: feePayer.PublicKey,
Mint: mint,
AssociatedTokenAccount: ata,
}),
tokenprog.TransferChecked(tokenprog.TransferCheckedParam{
From: aliceTokenRandomTokenPubkey,
To: ata,
Mint: mint,
Auth: alice.PublicKey,
Signers: []common.PublicKey{},
Amount: 1e8,
Decimals: 8,
}),
tokenmeta.CreateMasterEditionV3(tokenmeta.CreateMasterEditionParam{
Edition: tokenMasterEditionPubkey,
Mint: mint,
UpdateAuthority: feePayer.PublicKey,
MintAuthority: feePayer.PublicKey,
Metadata: tokenMetadataPubkey,
Payer: feePayer.PublicKey,
MaxSupply: pointer.Uint64(0),
}),
},
}),
Signers: []types.Account{feePayer, alice},
})
if err != nil {
log.Fatalf("failed to new tx, err: %v", err)
}
txhash, err := c.SendTransaction(context.Background(), tx)
if err != nil {
log.Fatalf("send raw tx error, err: %v\n", err)
}
log.Println("txhash:", txhash)
}
this code is used to mint a NFT. please read the tour again. you're still not get the main idea. 43xqaQkf8N95Af64ZqafbcQsPWdKqy5BRWxH7FFYomqX
can't be a token receiver. you should create a token account then transfer token to the account.
I understand sir.. But i have not used Mint function instead I have used TransferChecked as you suggested and also I have tried to mimic the MintNFT code as the recipient/buyer will also need an Token account and Ass Tkn account along with a CreateMetadataAccountV2 to store/receive the nft from the owner as it has minted on these aspects
I tried to use https://portto.github.io/solana-go-sdk/tour/token-transfer.html but the transfer is not happening with the metadata and its shows "Unknown Token"
Do have a similar kind of example for transfer nft as you have done it for Mint NFT(https://portto.github.io/solana-go-sdk/nft/mint-a-nft.html)
Unknown Token
?Thanks again for continuous support, Here is my code I have tried to make my code more pretty and readable sir.
Summary of my process:
My code
func main() {
//43xqaQkf8N95Af64ZqafbcQsPWdKqy5BRWxH7FFYomqX var feePayer, _ = types.AccountFromBase58("")
// 7s6Ro1mBBmmKmP2QDT2zzuCMqS6AVCgBQi1mRnsjX4QG var currentOwner, _ = types.AccountFromBase58("")
var currentTokenAccountPublickey = common.PublicKeyFromString("DEdpuTdsSk5uBkALtiCZjLBzFUozpJ6nAdh8Vi937ppb")
c := client.NewClient(rpc.DevnetRPCEndpoint)
mintNew := types.NewAccount()
log.Printf("NFT: %v\n", mintNew.PublicKey.ToBase58())
//Create an assocaited account for the feepayer/new buyer
ata, _, err := common.FindAssociatedTokenAddress(feePayer.PublicKey, mintNew.PublicKey)
if err != nil {
log.Fatalf("find ata error, err: %v", err)
}
log.Println("ata:", ata.ToBase58())
res, err := c.GetLatestBlockhash(context.Background())
if err != nil {
log.Fatalf("get recent block hash error, err: %v\n", err)
}
tx1, err := types.NewTransaction(types.NewTransactionParam{
Message: types.NewMessage(types.NewMessageParam{
FeePayer: feePayer.PublicKey,
RecentBlockhash: res.Blockhash,
Instructions: []types.Instruction{
assotokenprog.CreateAssociatedTokenAccount(assotokenprog.CreateAssociatedTokenAccountParam{
Funder: feePayer.PublicKey,
Owner: feePayer.PublicKey,
Mint: mintNew.PublicKey,
AssociatedTokenAccount: ata,
}),
tokenprog.TransferChecked(tokenprog.TransferCheckedParam{
From: currentTokenAccountPublickey, //Current tokenpublicaddress
To: ata, //New created assocated account for feepayer
Mint: mintNew.PublicKey, //new mint for the token
Auth: currentOwner.PublicKey,
Signers: []common.PublicKey{},
Amount: 1e8,
Decimals: 8,
}),
},
}),
Signers: []types.Account{feePayer, currentOwner},
})
if err != nil {
log.Fatalf("generate tx error, err: %v\n", err)
}
txhash1, err := c.SendTransaction(context.Background(), tx1)
if err != nil {
log.Fatalf("send raw tx error, err: %v\n", err)
}
log.Println("txhash:", txhash1)
}
My error {"code":-32002,"message":"Transaction simulation failed: Error processing Instruction 0: incorrect program id for instruction","data":{"accounts":null,"err":{"InstructionError":[0,"IncorrectProgramId"]},"logs":["Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]","Program log: Create","Program 11111111111111111111111111111111 invoke [2]","Program 11111111111111111111111111111111 success","Program log: Initialize the associated token account","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]","Program log: Instruction: InitializeAccount3","Program log: Error: IncorrectProgramId","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2392 of 387748 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: incorrect program id for instruction","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 14644 of 400000 compute units","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: incorrect program id for instruction"],"unitsConsumed":0}}
The nft token that I'm transferring is Af415cxd67Jo4eQNzB2c7Zr5oCP9jBX4UJdt4XCW8vbf
if you would like to transfer the token Af415cxd67Jo4eQNzB2c7Zr5oCP9jBX4UJdt4XCW8vbf
, you should replace all mintNew.PublicKey
in your code with common.PublicKeyFromString("Af415cxd67Jo4eQNzB2c7Zr5oCP9jBX4UJdt4XCW8vbf")
still error exists sir .. send raw tx error, err: rpc response error: {"code":-32002,"message":"Transaction simulation failed: Error processing Instruction 1: custom program error: 0x1","data":{"accounts":null,"err":{"InstructionError":[1,{"Custom":1}]},"logs":["Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]","Program log: Create","Program 11111111111111111111111111111111 invoke [2]","Program 11111111111111111111111111111111 success","Program log: Initialize the associated token account","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]","Program log: Instruction: InitializeAccount3","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2933 of 387748 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 15808 of 400000 compute units","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]","Program log: Instruction: TransferChecked","Program log: Error: insufficient funds","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2828 of 384192 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: custom program error: 0x1"],"unitsConsumed":15808}} exit status 1
even though i have enough funds in feepayer its giving me this error
Amount = 1 Decimal = 0
Thank it worked but for the first transfer only next time when I transfer to another account from the current ower it fails Example- https://explorer.solana.com/address/Fvpm4DWABgtPvtd7Ku8qKMbtnH5umXJZdfC3XSMWwv2L?cluster=devnet
So I have done the transfer from Account 1 to Account 2
Account 1
Account Address
HyMy4khSDqaEHbHfgXgEanoKszGcZV11TJfLgV2KNBGE
Mint
Fvpm4DWABgtPvtd7Ku8qKMbtnH5umXJZdfC3XSMWwv2L
Owner
43xqaQkf8N95Af64ZqafbcQsPWdKqy5BRWxH7FFYomqX
Account 2
Account Address
8td7noCBesuf6VAkzTELbfW4gAESFvWpTbjFAyw4hS6w
Mint
Fvpm4DWABgtPvtd7Ku8qKMbtnH5umXJZdfC3XSMWwv2L
Owner
7s6Ro1mBBmmKmP2QDT2zzuCMqS6AVCgBQi1mRnsjX4QG
And trying to transfer to Account 3- 4855uPpQwTAYaqXTRdv8PHb7QjYe57CXTHsE9L9U2zUS
But it gives me this error E 2022-06-23T07:45:13.7830662Z [86467663] default: unable to Send Transaction%!(EXTRA *errors.errorString=rpc response error: {"code":-32002,"message":"Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0","data":{"accounts":null,"err":{"InstructionError":[0,{"Custom":0}]},"logs":["Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]","Program log: Create","Program 11111111111111111111111111111111 invoke [2]","Allocate: account Address { address: HyMy4khSDqaEHbHfgXgEanoKszGcZV11TJfLgV2KNBGE, base: None } already in use","Program 11111111111111111111111111111111 failed: custom program error: 0x0","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 6576 of 400000 compute units","Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: custom program error: 0x0"],"unitsConsumed":0}}) E 2022-06-23T07:45:13.7830662Z [ea66dbfc-3039-16fb-b5ed-0a0027000011] default: {"errors":{"message":"Unable to Send Transaction","code":4002,"err":"rpc response error: {\"code\":-32002,\"message\":\"Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0\",\"data\":{\"accounts\":null,\"err\":{\"InstructionError\":[0,{\"Custom\":0}]},\"logs\":[\"Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]\",\"Program log: Create\",\"Program 11111111111111111111111111111111 invoke [2]\",\"Allocate: account Address { address: HyMy4khSDqaEHbHfgXgEanoKszGcZV11TJfLgV2KNBGE, base: None } already in use\",\"Program 11111111111111111111111111111111 failed: custom program error: 0x0\",\"Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 6576 of 400000 compute units\",\"Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: custom program error: 0x0\"],\"unitsConsumed\":0}}"}} {task:SolanaTransferNft flow:"Order Entry"}
My code func main() {
//4855uPpQwTAYaqXTRdv8PHb7QjYe57CXTHsE9L9U2zUS
var feePayer, _ = types.AccountFromBase58("")
// 7s6Ro1mBBmmKmP2QDT2zzuCMqS6AVCgBQi1mRnsjX4QG
var currentOwner, _ = types.AccountFromBase58("")
var currentTokenAccountPublickey = common.PublicKeyFromString("8td7noCBesuf6VAkzTELbfW4gAESFvWpTbjFAyw4hS6w")
c := client.NewClient(rpc.DevnetRPCEndpoint)
mintNew := common.PublicKeyFromString("Fvpm4DWABgtPvtd7Ku8qKMbtnH5umXJZdfC3XSMWwv2L")
log.Printf("NFT: %v\n", mintNew.PublicKey.ToBase58())
//Create an assocaited account for the feepayer/new buyer
ata, _, err := common.FindAssociatedTokenAddress(feePayer.PublicKey, mintNew.PublicKey)
if err != nil {
log.Fatalf("find ata error, err: %v", err)
}
log.Println("ata:", ata.ToBase58())
res, err := c.GetLatestBlockhash(context.Background())
if err != nil {
log.Fatalf("get recent block hash error, err: %v\n", err)
}
tx1, err := types.NewTransaction(types.NewTransactionParam{
Message: types.NewMessage(types.NewMessageParam{
FeePayer: feePayer.PublicKey,
RecentBlockhash: res.Blockhash,
Instructions: []types.Instruction{
assotokenprog.CreateAssociatedTokenAccount(assotokenprog.CreateAssociatedTokenAccountParam{
Funder: feePayer.PublicKey,
Owner: feePayer.PublicKey,
Mint: mintNew.PublicKey,
AssociatedTokenAccount: ata,
}),
tokenprog.TransferChecked(tokenprog.TransferCheckedParam{
From: currentTokenAccountPublickey, //Current tokenpublicaddress
To: ata, //New created assocated account for feepayer
Mint: mintNew.PublicKey, //new mint for the token
Auth: currentOwner.PublicKey,
Signers: []common.PublicKey{},
Amount: 1,
Decimals: 0,
}),
},
}),
Signers: []types.Account{feePayer, currentOwner},
})
if err != nil {
log.Fatalf("generate tx error, err: %v\n", err)
}
txhash1, err := c.SendTransaction(context.Background(), tx1)
if err != nil {
log.Fatalf("send raw tx error, err: %v\n", err)
}
log.Println("txhash:", txhash1)
}
error message said: "Allocate: account Address { address: HyMy4khSDqaEHbHfgXgEanoKszGcZV11TJfLgV2KNBGE, base: None } already in use"
if the account has already initialized, you can't create it again.
I'm going to close this issue. Feel free to open another one about SDK problems.
Hi. I was trying to execute the transfer NFT functionality ... But continuously running into errors
failed to send tx, err: rpc response error: {"code":-32002,"message":"Transaction simulation failed: Transaction loads a writable account that cannot be written","data":{"accounts":null,"err":"InvalidWritableAccount","logs":[],"unitsConsumed":0}} exit status 1
Could you give an example code for transfer like you have provided for Mint NFT? So that I can find out where I'm going wrong