repository
0.0.0-20241119035759-3968f949f06e
Repository: https://github.com/donutnomad/solana-web3.git
Documentation: pkg.go.dev
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# README
Solana Web3 Library (Golang)
This is a Go library for interacting with the Solana blockchain, inspired by the official @solana/web3.js JavaScript library. It provides a simple and easy-to-use API for building applications on the Solana network using Go.
Features
- Solana RPC Methods
- Transfer SOL, Token, Token2022
- Token2022 Extensions
- Metaplex Token Metadata
- Transaction creation and signing
- Easy to create a Token
Installation
To install the library, use go get
:
go get -u github.com/donutnomad/solana-web3
Web3
Usage
package main
import "context"
import "github.com/donutnomad/solana-web3/web3"
import "github.com/donutnomad/solana-web3/web3kit"
func main() {
client, err := web3.NewConnection(web3.Devnet.Url(), &web3.ConnectionConfig{
Commitment: &web3.CommitmentConfirmed,
})
if err != nil {
panic(err)
}
// generate a random key
var keypair = web3.Keypair.Generate()
_ = keypair
// get minimum balance for rent exemption
rent, err := client.GetMinimumBalanceForRentExemption(0, nil)
if err != nil {
panic(err)
}
_ = rent
// transfer sol/token/token2022
// More: https://github.com/donutnomad/solana-web3/tree/main/example/transfer_sol
signature, err := web3kit.Token.Transfer(context.Background(), client,
owner, owner, toOwner, mint, amount, tokenProgramId, true, web3.ConfirmOptions{
SkipPreflight: web3.Ref(false),
PreflightCommitment: &commitment,
Commitment: &commitment,
})
if err != nil {
panic(err)
}
// get token name,symbol,logo
var mint = web3.MustPublicKey("FH3i2zWEZRKQVkdqKknkfXzYgrGSTcc48VnwoJduf2o1")
name, symbol, logo, err := web3kit.Token.GetTokenName(context.Background(),
client, mint, &web3.CommitmentProcessed,
)
if err != nil {
panic(err)
}
_ = name
_ = symbol
_ = logo
}
Examples
This table provides an overview of the examples available in the examples directory.
Example | Description |
---|---|
balance | An example to retrieve the SOL balance of a user. |
parse | An example to parse SOL/Token/Token2022 transfers on the blockchain. |
transfer_sol | An example to send SOL tokens. |
transfer_token | An example to send SPL TOKEN tokens. |
transfer_token_2022 | An example to send SPL TOKEN 2022 tokens. |
create_token | An example to create solana token with metadata. |
create_token_2022 | An example to create solana token 2022 with metadata. |
Programs
Program | Description |
---|---|
Metaplex Token Metadata | Metaplex Token Metadata https://github.com/metaplex-foundation/mpl-token-metadata |
Associated Token Account | Solana Token Associated Token Account https://github.com/solana-labs/solana-program-library/tree/master/associated-token-account/program |
Token Program 2022 | Solana Token Program 2022. https://github.com/solana-labs/solana-program-library/tree/master/token/program-2022 Supported Extensions:cpi_guard,default_account_state...[More](#Token Program 2022 Extensions) |
Token Program | Solana Token Program https://github.com/solana-labs/solana-program-library/tree/master/token/program |
Token Program 2022 Metadata | Token Metadata for Token Program 2022 https://github.com/solana-labs/solana-program-library/tree/master/token-metadata |
Token Program 2022 Extensions
-
cpi_guard
-
default_account_state
-
group_member_pointer
-
group_pointer
-
immutable_owner
-
interest_bearing_mint
-
memo_transfer
-
metadata_pointer
-
mint_close_authority
-
non_transferable
-
permanent_delegate
-
token_group
-
transfer_fee
-
transfer_hook
-
confidential_transfer
-
confidential_transfer_fee
Documentation
Full documentation is available on pkg.go.dev.
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/your-feature
) - Create a new Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
This library was inspired by and based on the official @solana/web3.js library and the github.com/gagliardetto repository.