Comments (6)
for now you can try:
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/sysprog"
"github.com/portto/solana-go-sdk/rpc"
"github.com/portto/solana-go-sdk/types"
)
// you can fill your key here
var feePayer, _ = types.AccountFromBytes([]byte{178, 244, 76, 4, 247, 41, 113, 40, 111, 103, 12, 76, 195, 4, 100, 123, 88, 226, 37, 56, 209, 180, 92, 77, 39, 85, 78, 202, 121, 162, 88, 29, 125, 155, 223, 107, 139, 223, 229, 82, 89, 209, 27, 43, 108, 205, 144, 2, 74, 159, 215, 57, 198, 4, 193, 36, 161, 50, 160, 119, 89, 240, 102, 184})
// you can fill your key here
var alice, _ = types.AccountFromBytes([]byte{196, 114, 86, 165, 59, 177, 63, 87, 43, 10, 176, 101, 225, 42, 129, 158, 167, 43, 81, 214, 254, 28, 196, 158, 159, 64, 55, 123, 48, 211, 78, 166, 127, 96, 107, 250, 152, 133, 208, 224, 73, 251, 113, 151, 128, 139, 86, 80, 101, 70, 138, 50, 141, 153, 218, 110, 56, 39, 122, 181, 120, 55, 86, 185})
func main() {
c := client.NewClient(rpc.DevnetRPCEndpoint)
// to fetch recent blockhash
res, err := c.GetRecentBlockhash(context.Background())
if err != nil {
log.Fatalf("get recent block hash error, err: %v\n", err)
}
// create a message
message := types.NewMessage(types.NewMessageParam{
FeePayer: feePayer.PublicKey,
RecentBlockhash: res.Blockhash,
Instructions: []types.Instruction{
{
ProgramID: common.PublicKeyFromString("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),
Accounts: []types.AccountMeta{
{PubKey: alice.PublicKey, IsSigner: true, IsWritable: false},
},
Data: []byte("Hello World"), // you memo here
},
sysprog.Transfer(sysprog.TransferParam{
From: alice.PublicKey,
To: common.PublicKeyFromString("2xNweLHLqrbx4zo1waDvgWJHgsUpPj8Y8icbAFeR4a8i"),
Amount: 1e8,
}),
},
})
// create tx by message + signer
tx, err := types.NewTransaction(types.NewTransactionParam{
Message: message,
Signers: []types.Account{feePayer, alice},
})
if err != nil {
log.Fatalf("failed to new transaction, err: %v", err)
}
// send tx
txhash, err := c.SendTransaction(context.Background(), tx)
if err != nil {
log.Fatalf("failed to send tx, err: %v", err)
}
log.Println("txhash:", txhash)
}
example tx here: https://explorer.solana.com/tx/4kDgg6AghQ7j1uT3RjduWMayN7GhCTmKmvMzrMGcncRYVgVM1UnUF8cpJssGHfZbY9LoRPwjEdmmMFdJChGowAjA?cluster=devnet
I will add memo program's instruction to this sdk in next few days.
from solana-go-sdk.
got it. thank you so much.
from solana-go-sdk.
@yihau
I tried []byte type as data, get error: Invalid UTF-8
must use UTF-8 encode ?
How to use not-UTF-8 encode type ?
from solana-go-sdk.
I think it should be a UTF-8 string to this program.
here is the doc https://spl.solana.com/memo
The Memo program is a simple program that validates a string of UTF-8 encoded characters and verifies that any accounts provided are signers of the transaction.
from solana-go-sdk.
thank you again.
from solana-go-sdk.
there is an example for how to build a memo via this SDK.
thank you!
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.