Comments (3)
Hi!
For now you can use the code below
package main
import (
"context"
"crypto/ed25519"
"fmt"
"github.com/portto/solana-go-sdk/client"
"github.com/portto/solana-go-sdk/client/rpc"
"github.com/portto/solana-go-sdk/common"
"github.com/portto/solana-go-sdk/types"
)
func main() {
// connection
c := client.NewClient(rpc.DevnetRPCEndpoint)
// fee payer
feePayer := types.AccountFromPrivateKeyBytes([]byte{})
// compose message
message := types.NewMessage(
feePayer.PublicKey,
[]types.Instruction{},
"RECNET BLOCK HASH HERE",
)
// serialize message for signing
serilizedMessage, err := message.Serialize()
if err != nil {
// handle error here
}
// create tx with signatures
tx, err := types.CreateTransaction(
message,
map[common.PublicKey]types.Signature{
feePayer.PublicKey: ed25519.Sign(feePayer.PrivateKey, serilizedMessage),
// other pubkey: other sig
})
if err != nil {
// handle error here
}
// serialize tx
rawTx, err := tx.Serialize()
if err != nil {
// handle error here
}
// send it
sig, err := c.SendRawTransaction(context.Background(), rawTx)
if err != nil {
// handle error here
}
fmt.Println(sig)
}
I will refactor for this steps. I think it is so clumsy.
from solana-go-sdk.
Thanks for the fast response, yep that's exactly what I am looking for!
from solana-go-sdk.
I've added a new way to make the process more elegant at v1.7.0
package main
import (
"context"
"fmt"
"github.com/portto/solana-go-sdk/client"
"github.com/portto/solana-go-sdk/client/rpc"
"github.com/portto/solana-go-sdk/common"
"github.com/portto/solana-go-sdk/program/sysprog"
"github.com/portto/solana-go-sdk/types"
)
var feePayer = types.AccountFromPrivateKeyBytes()
func main() {
// connection
c := client.NewClient(rpc.DevnetRPCEndpoint)
a := types.NewAccount()
message := types.NewMessage(
feePayer.PublicKey,
[]types.Instruction{
sysprog.CreateAccount(
feePayer.PublicKey,
a.PublicKey,
common.SystemProgramID,
1e9,
1,
),
},
"RECENT BLOCK HASH HERE",
)
rawMessage, err := message.Serialize()
if err != nil {
// handle error
}
// you can pass signer here
tx, err := types.NewTransaction(message, []types.Account{feePayer})
if err != nil {
// handle error
}
// or add signature later!
tx.AddSignature(a.Sign(rawMessage))
sig, err := c.SendTransaction2(context.Background(), tx)
if err != nil {
// handle error
}
fmt.Println(sig)
}
there are two new function
- AddSignature => you can add extra sig to tx directly, no pubkey => sig anymore 🎉
- SendTransaction2 => you can pass tx struct to it and it will send the tx.
from solana-go-sdk.
Related Issues (20)
- 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
- Failing to deserialize token metadata HOT 3
- Error 32002 when creating associated token account HOT 4
- Docs incorrectly uses system.transfer for token transfers HOT 1
- How to deploy smart contract/program? HOT 1
- I cannot find how to confirm a transaction status on the client... HOT 1
- Add new Instructions to already existing transactions HOT 2
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.