Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make a token transaction on MainnetRPCEndpoint, such as BOME #177

Open
godlovericea opened this issue Oct 25, 2024 · 2 comments
Open

Comments

@godlovericea
Copy link

Signers: []types.Account{feePayer}:
2024/10/25 20:11:13 send raw tx error, err: {"code":-32003,"message":"Transaction signature verification failure","data":null}

@godlovericea
Copy link
Author

func Make_BOME_Tx() {
	feePayer, _ := types.AccountFromHex("***")
	alice, _ := types.AccountFromHex("***")
	// feePayer address: 79fVLECJ2p5BDFBTA7a9VEEsRdvg7QkV4mS7hBZJfSAz
	fmt.Println("feePayer address:", feePayer.PublicKey.ToBase58())
	// alice address: 7kQAKjpbV2uzcf9YVcej1dauYxGZvPsV2pSbxYLvri1N
	fmt.Println("alice address:", alice.PublicKey.ToBase58())
	// BOME
	var mintPubkey = common.PublicKeyFromString("ukHH6c7mMyiWCf1b9pnWe25TSpkDDt3H5pQZgZ74J82")
	ata, nonce, err := common.FindAssociatedTokenAddress(feePayer.PublicKey, mintPubkey)
	if err != nil {
		log.Fatalf("find ata error, err: %v", err)
	}
	fmt.Println("ata:", ata.ToBase58())
	// ata: 3s2ZDoWzkzg24uGyoRVPZLVCoh5Lo9s1HEZZ49zjYXQB
	var aliceTokenRandomTokenPubkey = common.PublicKeyFromString("3s2ZDoWzkzg24uGyoRVPZLVCoh5Lo9s1HEZZ49zjYXQB")
	fmt.Println("aliceTokenRandomTokenPubkey:", aliceTokenRandomTokenPubkey)
	// aliceTokenRandomTokenPubkey: 3s2ZDoWzkzg24uGyoRVPZLVCoh5Lo9s1HEZZ49zjYXQB
	c := client.NewClient(rpc.MainnetRPCEndpoint)
	fmt.Println("nonce:", nonce)
	// nonce: 255
	res, err := c.GetLatestBlockhash(context.Background())
	if err != nil {
		log.Fatalf("get recent block hash error, err: %v\n", err)
	}
	balance, err := c.GetBalance(
		context.TODO(),
		feePayer.PublicKey.ToBase58(),
	)
	if err != nil {
		log.Fatalf("failed to get balance, err: %v", err)
	}
	fmt.Printf("balance: %v\n", balance)
	// balance 56795720
	tokenBalance, err := c.GetTokenAccountBalance(
		context.Background(),
		ata.ToBase58(),
	)
	if err != nil {
		log.Fatalln("get balance error", err)
	}
	// the smallest unit like lamports
	fmt.Println("balance", tokenBalance.Amount)
	// balance 230000000
	// the decimals of mint which token account holds
	fmt.Println("decimals", tokenBalance.Decimals)
	// decimals 6
	txs, err := types.NewTransaction(types.NewTransactionParam{
		Message: types.NewMessage(types.NewMessageParam{
			FeePayer:        feePayer.PublicKey,
			RecentBlockhash: res.Blockhash,
			Instructions: []types.Instruction{
				token.TransferChecked(token.TransferCheckedParam{
					From:     ata,
					To:       common.PublicKeyFromString("47ioV9HJe4ZXFXLMNjpYrUxVGuuuRcs77K196ARLi2zD"),
					Mint:     mintPubkey,
					Auth:     common.PublicKey{},
					Signers:  []common.PublicKey{},
					Amount:   1000000,
					Decimals: 6,
				}),
			},
		}),
		Signers: []types.Account{feePayer},
	})
	if err != nil {
		log.Fatalf("generate tx error, err: %v\n", err)
	}
	txhash_BOME, err := c.SendTransaction(context.Background(), txs)
	if err != nil {
		log.Fatalf("send raw tx error, err: %v\n", err)
	}
	// 2024/10/25 20:15:17 send raw tx error, err: {"code":-32003,"message":"Transaction signature verification failure","data":null}
	log.Println("txhash_BOME:", txhash_BOME)
}

@godlovericea
Copy link
Author

godlovericea commented Oct 25, 2024

I hava been made sol tx successufully,
but the token is failure, please help me.
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant