-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
6,656 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: docs | ||
|
||
on: | ||
# trigger deployment on every push to main branch | ||
push: | ||
branches: [main] | ||
# trigger deployment manually | ||
workflow_dispatch: | ||
|
||
jobs: | ||
docs: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
# fetch all commits to get last updated time or other git log info | ||
fetch-depth: 0 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
# choose node.js version to use | ||
node-version: "16" | ||
|
||
# run build script | ||
- name: install dependencies | ||
working-directory: ./docs | ||
run: npm install | ||
|
||
# run build script | ||
- name: Build VuePress site | ||
working-directory: ./docs | ||
run: npm run docs:build | ||
|
||
# please check out the docs of the workflow for more details | ||
# @see https://github.com/crazy-max/ghaction-github-pages | ||
- name: Deploy to GitHub Pages | ||
uses: crazy-max/ghaction-github-pages@v2 | ||
with: | ||
# deploy to gh-pages branch | ||
target_branch: gh-pages | ||
# deploy the default output dir of VuePress | ||
build_dir: docs/src/.vuepress/dist | ||
env: | ||
# @see https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.temp | ||
.cache |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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" | ||
) | ||
|
||
// FUarP2p5EnxD66vVDL4PWRoWMzA56ZVHG24hpEDFShEz | ||
var feePayer, _ = types.AccountFromBase58("4TMFNY9ntAn3CHzguSAvDNLPRoQTaK3sWbQQXdDXaE6KWRBLufGL6PJdsD2koiEe3gGmMdRK3aAw7sikGNksHJrN") | ||
|
||
// 9aE476sH92Vz7DMPyq5WLPkrKWivxeuTKEFKd2sZZcde | ||
var alice, _ = types.AccountFromBase58("4voSPg3tYuWbKzimpQK9EbXHmuyy5fUrtXvpLDMLkmY6TRncaTHAKGD8jUg3maB5Jbrd9CkQg4qjJMyN6sQvnEF2") | ||
|
||
func main() { | ||
c := client.NewClient(rpc.DevnetRPCEndpoint) | ||
|
||
// to fetch recent blockhash | ||
recentBlockhashResponse, err := c.GetRecentBlockhash(context.Background()) | ||
if err != nil { | ||
log.Fatalf("failed to get recent blockhash, err: %v", err) | ||
} | ||
|
||
// create a transfer tx | ||
tx, err := types.NewTransaction(types.NewTransactionParam{ | ||
Signers: []types.Account{feePayer, alice}, | ||
Message: types.NewMessage(types.NewMessageParam{ | ||
FeePayer: feePayer.PublicKey, | ||
RecentBlockhash: recentBlockhashResponse.Blockhash, | ||
Instructions: []types.Instruction{ | ||
sysprog.Transfer(sysprog.TransferParam{ | ||
From: alice.PublicKey, | ||
To: common.PublicKeyFromString("2xNweLHLqrbx4zo1waDvgWJHgsUpPj8Y8icbAFeR4a8i"), | ||
Amount: 1e8, // 0.1 SOL | ||
}), | ||
}, | ||
}), | ||
}) | ||
if err != nil { | ||
log.Fatalf("failed to new a 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/portto/solana-go-sdk/client" | ||
"github.com/portto/solana-go-sdk/rpc" | ||
) | ||
|
||
func main() { | ||
c := client.NewClient(rpc.DevnetRPCEndpoint) | ||
sig, err := c.RequestAirdrop( | ||
context.TODO(), | ||
"9qeP9DmjXAmKQc4wy133XZrQ3Fo4ejsYteA7X4YFJ3an", // address | ||
1e9, // lamports (1 SOL = 10^9 lamports) | ||
) | ||
if err != nil { | ||
log.Fatalf("failed to request airdrop, err: %v", err) | ||
} | ||
fmt.Println(sig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/mr-tron/base58" | ||
"github.com/portto/solana-go-sdk/pkg/hdwallet" | ||
"github.com/portto/solana-go-sdk/types" | ||
"github.com/tyler-smith/go-bip39" | ||
) | ||
|
||
func main() { | ||
// create a new account | ||
{ | ||
account := types.NewAccount() | ||
fmt.Println(account.PublicKey.ToBase58()) | ||
fmt.Println(base58.Encode(account.PrivateKey)) | ||
} | ||
|
||
// from a base58 pirvate key | ||
{ | ||
account, _ := types.AccountFromBase58("28WJTTqMuurAfz6yqeTrFMXeFd91uzi9i1AW6F5KyHQDS9siXb8TquAuatvLuCEYdggyeiNKLAUr3w7Czmmf2Rav") | ||
fmt.Println(account.PublicKey.ToBase58()) | ||
} | ||
|
||
// from a private key bytes | ||
{ | ||
account, _ := types.AccountFromBytes([]byte{ | ||
56, 125, 59, 118, 230, 173, 152, 169, 197, 34, | ||
168, 187, 217, 160, 119, 204, 124, 69, 52, 136, | ||
214, 49, 207, 234, 79, 70, 83, 224, 1, 224, 36, | ||
247, 131, 83, 164, 85, 139, 215, 183, 148, 79, | ||
198, 74, 93, 156, 157, 208, 99, 221, 127, 51, | ||
156, 43, 196, 101, 144, 104, 252, 221, 108, | ||
245, 104, 13, 151, | ||
}) | ||
fmt.Println(account.PublicKey.ToBase58()) | ||
} | ||
|
||
// from bip 39 (solana cli tool) | ||
{ | ||
mnemonic := "pill tomorrow foster begin walnut borrow virtual kick shift mutual shoe scatter" | ||
seed := bip39.NewSeed(mnemonic, "") // (mnemonic, password) | ||
account, _ := types.AccountFromSeed(seed[:32]) | ||
fmt.Println(account.PublicKey.ToBase58()) | ||
} | ||
|
||
// from bip 44 (phantom) | ||
{ | ||
mnemonic := "neither lonely flavor argue grass remind eye tag avocado spot unusual intact" | ||
seed := bip39.NewSeed(mnemonic, "") // (mnemonic, password) | ||
path := `m/44'/501'/0'/0'` | ||
derivedKey, _ := hdwallet.Derived(path, seed) | ||
account, _ := types.AccountFromSeed(derivedKey.PrivateKey) | ||
fmt.Printf("%v => %v\n", path, account.PublicKey.ToBase58()) | ||
|
||
// others | ||
for i := 1; i < 10; i++ { | ||
path := fmt.Sprintf(`m/44'/501'/%d'/0'`, i) | ||
derivedKey, _ := hdwallet.Derived(path, seed) | ||
account, _ := types.AccountFromSeed(derivedKey.PrivateKey) | ||
fmt.Printf("%v => %v\n", path, account.PublicKey.ToBase58()) | ||
} | ||
/* | ||
m/44'/501'/0'/0' => 5vftMkHL72JaJG6ExQfGAsT2uGVHpRR7oTNUPMs68Y2N | ||
m/44'/501'/1'/0' => GcXbfQ5yY3uxCyBNDPBbR5FjumHf89E7YHXuULfGDBBv | ||
m/44'/501'/2'/0' => 7QPgyQwNLqnoSwHEuK8wKy2Y3Ani6EHoZRihTuWkwxbc | ||
m/44'/501'/3'/0' => 5aE8UprEEWtpVskhxo3f8ETco2kVKiZT9SS3D5Lcg8s2 | ||
m/44'/501'/4'/0' => 5n6afo6LZmzH1J4R38ZCaNSwaztLjd48nWwToLQkCHxp | ||
m/44'/501'/5'/0' => 2Gr1hWnbaqGXMghicSTHncqV7GVLLddNFJDC7YJoso8M | ||
m/44'/501'/6'/0' => BNMDY3tCyYbayMzBjZm8RW59unpDWcQRfVmWXCJhLb7D | ||
m/44'/501'/7'/0' => 9CySTpi4iC85gMW6G4BMoYbNBsdyJrfseHoGmViLha63 | ||
m/44'/501'/8'/0' => ApteF7PmUWS8Lzm6tJPkWgrxSFW5LwYGWCUJ2ByAec91 | ||
m/44'/501'/9'/0' => 6frdqXQAgJMyKwmZxkLYbdGjnYTvUceh6LNhkQt2siQp | ||
*/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"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" | ||
) | ||
|
||
var mintPubkey = common.PublicKeyFromString("F6tecPzBMF47yJ2EN6j2aGtE68yR5jehXcZYVZa6ZETo") | ||
|
||
func main() { | ||
c := client.NewClient(rpc.DevnetRPCEndpoint) | ||
|
||
getAccountInfoResponse, err := c.GetAccountInfo(context.TODO(), mintPubkey.ToBase58()) | ||
if err != nil { | ||
log.Fatalf("failed to get account info, err: %v", err) | ||
} | ||
|
||
mintAccount, err := tokenprog.MintAccountFromData(getAccountInfoResponse.Data) | ||
if err != nil { | ||
log.Fatalf("failed to parse data to a mint account, err: %v", err) | ||
} | ||
|
||
fmt.Printf("%+v\n", mintAccount) | ||
// {MintAuthority:9aE476sH92Vz7DMPyq5WLPkrKWivxeuTKEFKd2sZZcde Supply:0 Decimals:8 IsInitialized:true FreezeAuthority:<nil>} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/portto/solana-go-sdk/client" | ||
"github.com/portto/solana-go-sdk/rpc" | ||
) | ||
|
||
func main() { | ||
c := client.NewClient(rpc.DevnetRPCEndpoint) | ||
balance, err := c.GetBalance( | ||
context.TODO(), | ||
"9qeP9DmjXAmKQc4wy133XZrQ3Fo4ejsYteA7X4YFJ3an", | ||
) | ||
if err != nil { | ||
log.Fatalf("failed to request airdrop, err: %v", err) | ||
} | ||
fmt.Println(balance) | ||
} |
Oops, something went wrong.