solana-ruby-web3js 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2bd60b642f794a5923a3ff1d1b39e29e60aca6444445b0cf2e36e7393b18ff3
4
- data.tar.gz: 95a61aab91ec4eaacb94fdc671027a2005b320b938a7a2132dc0daf9b643d45b
3
+ metadata.gz: 731b11629fcf8aeccddb1041dd5380b72ca120dd3ad23fc8cf1884a963864a96
4
+ data.tar.gz: d2d42348b2eb8d58433aec922bdcb3bb1631ab119d52999d4d20d63ebcf545ff
5
5
  SHA512:
6
- metadata.gz: 85acebeaeaebce2d39fe74f7d931a7e339e1a773d73f4774003a06a84bed4f94343b4f41269ac4bd1b2c7fbd186145ccba7d8d25b35b9aadee9a2b9f9a56c06e
7
- data.tar.gz: 68b1d9bf25f64d1424e660387cc802e12842ea428547c4d4643b23489f2dab3db75c4d63a35d23159521b41634b11aef0befa9fa3193c2cf275f14f22412b70f
6
+ metadata.gz: ace60d58b990d3364ff3397c0719a81089a5c73af584094ad4d1a673d55be52a9a6d60dab0db910b8f41ef4e01ce55b551ee0404b3aa075a12f1e4440ec96cbc
7
+ data.tar.gz: 9a26564405175ab409799becfeb8ea00d275689990b3319d379d6ae9df5d1c025d4ef925d21068664ce46a71f62a5abb07935b5732aa9eb5196addea4a36b5fa
data/README.md CHANGED
@@ -463,3 +463,328 @@ The create_account helper allows creating a new account with specified parameter
463
463
  puts "Transaction Signature: #{response}"
464
464
  puts "New account created with Public Key: #{new_account_pubkey}"
465
465
 
466
+ ### SPL Token Account Creation
467
+
468
+ The create_associated_token_account helper allows you to create an associated token account for a specific mint and owner. This is necessary when dealing with SPL tokens on the Solana blockchain.
469
+
470
+ #### Requirements:
471
+
472
+ - **Payer Public key**: The public key of the account funding the creation.
473
+ - **Mint Public Key**: The public key of the SPL token mint.
474
+ - **Owner Public Key**: The public key of the owner for whom the associated token account is being created.
475
+ - **Recent Blockhash**: The latest blockhash for the transaction.
476
+
477
+ #### Example Usage:
478
+
479
+ require 'solana_ruby'
480
+
481
+ # Initialize the Solana client (defaults to Mainnet: https://api.mainnet-beta.solana.com)
482
+ client = SolanaRuby::HttpClient.new('https://api.devnet.solana.com')
483
+
484
+ # Fetch the recent blockhash
485
+ recent_blockhash = client.get_latest_blockhash["blockhash"]
486
+
487
+ # Load the keypair for the payer
488
+ payer_keypair = SolanaRuby::Keypair.load_keypair('InsertYourJsonFilePathHere')
489
+ payer_pubkey = payer_keypair.public_key
490
+
491
+ # Generate or load the owner keypair
492
+ owner_keypair = SolanaRuby::Keypair.generate
493
+ owner_pubkey = owner_keypair.public_key
494
+
495
+ puts "Owner Public Key: #{owner_pubkey}"
496
+ puts "Owner Private Key: #{owner_keypair.private_key}"
497
+
498
+ # Define the mint public key for the SPL token
499
+ mint_pubkey = "InsertMintPublicKeyHere"
500
+
501
+ # Create the associated token account transaction
502
+ transaction = SolanaRuby::TransactionHelper.create_associated_token_account(
503
+ payer_pubkey,
504
+ mint_pubkey,
505
+ owner_pubkey,
506
+ recent_blockhash
507
+ )
508
+
509
+ # Sign the transaction
510
+ transaction.sign([payer_keypair])
511
+
512
+ # Send the transaction
513
+ response = client.send_transaction(transaction.to_base64, { encoding: 'base64' })
514
+
515
+ # Output transaction results
516
+ puts "Transaction Signature: #{response}"
517
+
518
+ ### Close Account
519
+
520
+ The close_account helper allows you to close an associated token account on the Solana blockchain. Any remaining balance in the account is transferred to the specified destination account.
521
+
522
+ #### Requirements:
523
+
524
+ - **Account to Close**: The public key of the associated token account to be closed.
525
+ - **Destination Public Key**: The public key of the account receiving the remaining balance.
526
+ - **Owner Public Key**: The public key of the account owner who has permission to close the account.
527
+ - **Payer Public Key**: The public key of the account paying for the transaction fees.
528
+ - **Multi-Signers (Optional)**: An array of additional signer public keys if the account requires multiple signatures.
529
+ - **Recent Blockhash**: The latest blockhash for the transaction.
530
+
531
+ #### Example Usage:
532
+
533
+ require 'solana_ruby'
534
+
535
+ # Initialize the Solana client (defaults to Mainnet: https://api.mainnet-beta.solana.com)
536
+ client = SolanaRuby::HttpClient.new('https://api.devnet.solana.com')
537
+
538
+ # Fetch the recent blockhash
539
+ recent_blockhash = client.get_latest_blockhash["blockhash"]
540
+
541
+ # Load the keypairs
542
+ payer_keypair = SolanaRuby::Keypair.from_private_key("InsertPayerPrivateKeyHere")
543
+ owner_keypair = SolanaRuby::Keypair.from_private_key("InsertOwnerPrivateKeyHere")
544
+
545
+ payer_pubkey = payer_keypair[:public_key]
546
+ owner_pubkey = owner_keypair[:public_key]
547
+
548
+ # Define the associated token account to be closed and the destination account
549
+ account_to_close_pubkey = 'InsertAccountToClosePublicKeyHere' # Replace with the actual account to close
550
+ destination_pubkey = 'InsertDestinationPublicKeyHere' # Replace with the actual recipient address
551
+
552
+ # Multi-signers (if required)
553
+ # multi_signers = [SolanaRuby::Keypair.from_private_key("InsertAdditionalSignerPrivateKeyHere")]
554
+ multi_signers = []
555
+
556
+ # Extract public keys of multi-signers
557
+ multi_signer_pubkeys = multi_signers.map { |signer| signer[:public_key] }
558
+
559
+ # Create the close account transaction
560
+ transaction = SolanaRuby::TransactionHelper.close_account(
561
+ account_to_close_pubkey,
562
+ destination_pubkey,
563
+ owner_pubkey,
564
+ payer_pubkey,
565
+ multi_signer_pubkeys,
566
+ recent_blockhash
567
+ )
568
+
569
+ # Sign the transaction
570
+ transaction.sign([payer_keypair, owner_keypair])
571
+
572
+ # Send the transaction
573
+ response = client.send_transaction(transaction.to_base64, { encoding: 'base64' })
574
+
575
+ # Output transaction results
576
+ puts "Transaction Signature: #{response}"
577
+ puts "Closed account: #{account_to_close_pubkey}, funds sent to: #{destination_pubkey}"
578
+
579
+ ### Get Associated Token Address
580
+
581
+ The get_associated_token_address helper fetches the associated token account for a given mint address and owner public key. This is essential when interacting with SPL tokens to determine where tokens are held.
582
+
583
+ #### Requirements:
584
+
585
+ - **Mint Address**: The public key of the SPL token mint.
586
+ - **Owner Public Key**: The public key of the token holder.
587
+
588
+ #### Example Usage:
589
+
590
+ require 'solana_ruby'
591
+
592
+ # Define mint address and owner public key
593
+ mint_address = 'InsertMintPublicKeyHere'
594
+ owner_pubkey = 'InsertOwnerPublicKeyHere'
595
+
596
+ # Fetch associated token address
597
+ associated_token_address = SolanaRuby::TransactionHelpers::TokenAccount.get_associated_token_address(
598
+ mint_address,
599
+ owner_pubkey
600
+ )
601
+
602
+ puts "Associated Token Address: #{associated_token_address}"
603
+
604
+ ### Mint SPL Tokens
605
+
606
+ The mint_spl_tokens helper allows you to mint new SPL tokens to a specified destination account. This is useful for token creators who need to distribute newly minted tokens.
607
+
608
+ #### Requirements:
609
+
610
+ - **Mint Account Public Key**: The public key of the mint account.
611
+ - **Destination Account Public Key**: The associated token account where the newly minted tokens will be sent.
612
+ - **Mint Authority Public Key**: The public key of the authority allowed to mint new tokens.
613
+ - **Amount**: The number of tokens to mint (in the smallest unit, based on token decimals).
614
+ - **Multi-Signers (Optional)**: Additional signer public keys if multi-signature authorization is required.
615
+ - **Recent Blockhash**: The latest blockhash for the transaction.
616
+
617
+ #### Example Usage:
618
+
619
+ require 'solana_ruby'
620
+
621
+ # Initialize the Solana client (defaults to Mainnet: https://api.mainnet-beta.solana.com)
622
+ client = SolanaRuby::HttpClient.new('https://api.devnet.solana.com')
623
+
624
+ # Fetch the recent blockhash
625
+ recent_blockhash = client.get_latest_blockhash["blockhash"]
626
+
627
+ # Define the mint account and recipient
628
+ mint_account = "InsertMintPublicKeyHere"
629
+ destination_account = "InsertDestinationPublicKeyHere"
630
+
631
+ # Load the mint authority keypair
632
+ mint_authority = SolanaRuby::Keypair.load_keypair('InsertYourJsonFilePathHere')
633
+
634
+ puts "Mint Authority Public Key: #{mint_authority[:public_key]}"
635
+
636
+ # Define the amount to mint (in smallest units)
637
+ amount = 1_000_000_00_00 # Adjust based on token decimals
638
+
639
+ # Multi-signers (if required)
640
+ multi_signers = [] # Example: [additional_signer_pubkey]
641
+
642
+ # Create the mint transaction
643
+ transaction = SolanaRuby::TransactionHelper.mint_spl_tokens(
644
+ mint_account,
645
+ destination_account,
646
+ mint_authority[:public_key],
647
+ amount,
648
+ recent_blockhash,
649
+ multi_signers
650
+ )
651
+
652
+ # Sign the transaction with the mint authority
653
+ transaction.sign([mint_authority])
654
+
655
+ # Send the transaction
656
+ response = client.send_transaction(transaction.to_base64, { encoding: 'base64' })
657
+
658
+ # Output transaction results
659
+ puts "Transaction Signature: #{response}"
660
+ puts "Minted #{amount} tokens to: #{destination_account}"
661
+
662
+ ### Burn SPL Tokens
663
+
664
+ The burn_spl_tokens helper allows you to burn (destroy) a specified amount of SPL tokens from a token account. This is typically used to reduce the total supply of a token.
665
+
666
+ #### Requirements:
667
+
668
+ - **Token Account**: The associated token account holding the tokens to be burned..
669
+ - **Mint Address**: The mint address of the SPL token.
670
+ - **Owner**: The owner of the token account (must have authority to burn tokens).
671
+ - **Amount**: The number of tokens to burn (denominated in the smallest units).
672
+ - **Recent Blockhash**: The latest blockhash for the transaction.
673
+
674
+ #### Example Usage:
675
+
676
+ require 'solana_ruby'
677
+
678
+ # Initialize the Solana client (defaults to Mainnet: https://api.mainnet-beta.solana.com)
679
+ client = SolanaRuby::HttpClient.new('https://api.devnet.solana.com')
680
+
681
+ # Fetch the recent blockhash
682
+ recent_blockhash = client.get_latest_blockhash["blockhash"]
683
+
684
+ # Define token account and mint address
685
+ token_account = "InsertTokenAccountPublicKeyHere"
686
+ mint_address = "InsertMintPublicKeyHere"
687
+
688
+ # Load the mint authority keypair
689
+ mint_authority = SolanaRuby::Keypair.load_keypair('/path/to/id.json')
690
+ owner = mint_authority[:public_key]
691
+
692
+ # Define the amount to burn
693
+ amount = 500_000 # Tokens to burn in smallest units
694
+
695
+ # Create burn transaction
696
+ transaction = SolanaRuby::TransactionHelper.burn_spl_tokens(
697
+ token_account,
698
+ mint_address,
699
+ owner,
700
+ amount,
701
+ recent_blockhash
702
+ )
703
+
704
+ # Sign the transaction
705
+ transaction.sign([mint_authority])
706
+
707
+ # Send the transaction
708
+ response = client.send_transaction(transaction.to_base64, { encoding: 'base64' })
709
+
710
+ # Output transaction results
711
+ puts "Transaction Signature: #{response}"
712
+
713
+ ### Transfer SPL Tokens
714
+
715
+ The new_spl_token_transaction helper allows you to transfer SPL tokens from one associated token account to another.
716
+
717
+ #### Requirements:
718
+
719
+ - **Sender's Token Account**: The associated token account holding the tokens to be transferred.
720
+ - **Mint Address**: The mint address of the SPL token.
721
+ - **Receiver's Token Account**: The associated token account of the recipient.
722
+ - **Fee Payer:**: The account responsible for transaction fees.
723
+ - **Amount**: The number of tokens to mint (in the smallest unit, based on token decimals).
724
+ - **Decimals**: The decimal precision of the SPL token (e.g., 9 for SOL-based tokens).
725
+ - **Recent Blockhash**: The latest blockhash for the transaction.
726
+ - **Multi-Signers (Optional)**: List of additional required signers (if applicable).
727
+
728
+ #### Example Usage:
729
+
730
+ require 'solana_ruby'
731
+
732
+ # Initialize the Solana client
733
+ client = SolanaRuby::HttpClient.new('http://127.0.0.1:8899')
734
+
735
+ # Fetch the recent blockhash
736
+ recent_blockhash = client.get_latest_blockhash["blockhash"]
737
+
738
+ # Load the fee payer's keypair
739
+ fee_payer = SolanaRuby::Keypair.from_private_key('InsertFeePayerPrivateKeyHere')
740
+ fee_payer_pubkey = fee_payer[:public_key]
741
+
742
+ # Define the SPL token mint address
743
+ mint_address = 'InsertMintPublicKeyHere'
744
+
745
+ # Define sender and receiver public keys
746
+ sender_pubkey = 'InsertSenderPublicKeyHere'
747
+ receiver_pubkey = 'InsertReceiverPublicKeyHere'
748
+
749
+ # Fetch the associated token accounts
750
+ senders_token_account = SolanaRuby::TransactionHelpers::TokenAccount.get_associated_token_address(mint_address, sender_pubkey)
751
+ receivers_token_account = SolanaRuby::TransactionHelpers::TokenAccount.get_associated_token_address(mint_address, receiver_pubkey)
752
+
753
+ puts "Sender's Token Account: #{senders_token_account}"
754
+ puts "Receiver's Token Account: #{receivers_token_account}"
755
+
756
+ # Define the transfer amount and decimals
757
+ transfer_lamports = 1_000_000 # Amount in smallest units
758
+ decimals = 9 # Adjust based on token precision
759
+
760
+ # Multi-signers (Optional, default is an empty array)
761
+ # multi_signers = [
762
+ # SolanaRuby::Keypair.from_private_key('InsertMultiSigner1PrivateKeyHere'),
763
+ # SolanaRuby::Keypair.from_private_key('InsertMultiSigner2PrivateKeyHere')
764
+ # ]
765
+ # multi_signer_pubkeys = multi_signers.map { |signer| signer[:public_key] }
766
+ multi_signers = []
767
+
768
+ # Create the transaction
769
+ transaction = SolanaRuby::TransactionHelper.new_spl_token_transaction(
770
+ senders_token_account,
771
+ mint_address,
772
+ receivers_token_account,
773
+ fee_payer_pubkey,
774
+ transfer_lamports,
775
+ decimals,
776
+ recent_blockhash,
777
+ multi_signer_pubkeys
778
+ )
779
+
780
+ # Sign the transaction (Only fee payer, unless multi-signers are provided)
781
+ transaction.sign([fee_payer] + multi_signers)
782
+
783
+ # Send the transaction
784
+ puts "Sending transaction..."
785
+ response = client.send_transaction(transaction.to_base64, { encoding: 'base64' })
786
+
787
+ # Output transaction results
788
+ puts "Transaction Signature: #{response}"
789
+
790
+
@@ -42,6 +42,10 @@ module SolanaRuby
42
42
  spl_burn: {
43
43
  instruction: :uint8,
44
44
  amount: :uint64
45
+ },
46
+ # Close account layout (added here)
47
+ close_account: {
48
+ instruction: :uint8
45
49
  }
46
50
  }
47
51
 
@@ -82,6 +86,40 @@ module SolanaRuby
82
86
  transaction
83
87
  end
84
88
 
89
+ # Method to create a close account instruction
90
+ def self.close_account_instruction( account_to_close, destination, owner, payer, multi_signers)
91
+ # Encode the instruction data
92
+ instruction_data = encode_data(
93
+ INSTRUCTION_LAYOUTS[:close_account],
94
+ { instruction: 9 } # Close account instruction number is 9
95
+ )
96
+
97
+ signer = multi_signers.empty? ? payer : multi_signers
98
+ # Set up the keys for the close account instruction
99
+ keys = SolanaRuby::TransactionHelpers::TokenAccount.add_signers(
100
+ [{ pubkey: account_to_close, is_signer: false, is_writable: true },
101
+ { pubkey: destination, is_signer: false, is_writable: true }],
102
+ owner, signer)
103
+
104
+ # Return the instruction
105
+ create_instruction(keys, instruction_data)
106
+ end
107
+
108
+ # Method to close an account (helper)
109
+ def self.close_account(account_to_close, destination, owner, payer, multi_signers, recent_blockhash)
110
+ # Create the transaction
111
+ transaction = Transaction.new
112
+ transaction.set_fee_payer(payer)
113
+ transaction.set_recent_blockhash(recent_blockhash)
114
+
115
+ # Add the close account instruction to the transaction
116
+ instruction = close_account_instruction(account_to_close, destination, owner, payer, multi_signers)
117
+ transaction.add_instruction(instruction)
118
+
119
+ # Return the transaction for signing
120
+ transaction
121
+ end
122
+
85
123
  # Method to create a SOL transfer instruction
86
124
  def self.transfer_sol_instruction(from_pubkey, to_pubkey, lamports)
87
125
  fields = INSTRUCTION_LAYOUTS[:sol_transfer]
@@ -230,10 +268,10 @@ module SolanaRuby
230
268
  layout.deserialize(data)
231
269
  end
232
270
 
233
- def self.create_instruction(keys, data, toke_program_id = TOKEN_PROGRAM_ID)
271
+ def self.create_instruction(keys, data, token_program_id = TOKEN_PROGRAM_ID)
234
272
  TransactionInstruction.new(
235
273
  keys: keys,
236
- program_id: toke_program_id,
274
+ program_id: token_program_id,
237
275
  data: data
238
276
  )
239
277
  end
@@ -27,7 +27,7 @@ module SolanaRuby
27
27
  end
28
28
 
29
29
  def self.add_signers(keys, owner_or_authority, multi_signers)
30
- if multi_signers.any?
30
+ if multi_signers.is_a?(Array) && multi_signers.any?
31
31
  keys.push({ pubkey: owner_or_authority, is_signer: false, is_writable: false })
32
32
  multi_signers.each do |signer|
33
33
  pubkey = signer.is_a?(String) ? signer : signer.public_key
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolanaRuby
4
- VERSION = "2.0.2"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ require 'pry'
3
+
4
+ Dir[File.join(File.dirname(__dir__), 'lib/solana_ruby/*.rb')].each { |file| require file }
5
+ Dir[File.join(File.dirname(__dir__), 'lib/solana_ruby/**/*.rb')].each { |file| require file }
6
+
7
+ # SOL Transfer Testing Script
8
+
9
+ # Initialize the Solana client
10
+ client = SolanaRuby::HttpClient.new('http://127.0.0.1:8899')
11
+
12
+ # Fetch the recent blockhash
13
+ recent_blockhash = client.get_latest_blockhash["blockhash"]
14
+
15
+ # Assuming you already have the following public keys
16
+ payer = SolanaRuby::Keypair.from_private_key('7bcd98e0be17a23f5adbb199d614f5df28e2491ca9856a7efc276245d9d22f26')
17
+ payer_pubkey = payer[:public_key]
18
+ owner = SolanaRuby::Keypair.from_private_key('7bcd98e0be17a23f5adbb199d614f5df28e2491ca9856a7efc276245d9d22f26')
19
+ account_to_close_pubkey = 'bnKvAbZzNjF123Wa9g4yQNva5adLqj2fLNfipZ2KgP6' # associated token account closing address
20
+ destination_pubkey = 'DCm6PCsdRoEXzHUdHxXnJTP65gYSPK5p8h9Cui3quiQQ' # associated token account receiving address
21
+
22
+ # Create the transaction to close the account
23
+ transaction = SolanaRuby::TransactionHelper.close_account(
24
+ account_to_close_pubkey,
25
+ destination_pubkey,
26
+ owner[:public_key],
27
+ payer_pubkey,
28
+ [],
29
+ recent_blockhash
30
+ )
31
+
32
+ resp = transaction.sign([payer, owner])
33
+
34
+ puts "signature: #{resp}"
35
+
36
+ # Send the transaction
37
+ puts "Sending transaction..."
38
+ response = client.send_transaction(transaction.to_base64, { encoding: 'base64' })
39
+
40
+ # Output transaction results
41
+ puts "Transaction Signature: #{response}"
42
+
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
-
2
+ # require 'pry'
3
3
  Dir[File.join(File.dirname(__dir__), 'lib/solana_ruby/*.rb')].each { |file| require file }
4
4
  Dir[File.join(File.dirname(__dir__), 'lib/solana_ruby/**/*.rb')].each { |file| require file }
5
5
 
@@ -16,10 +16,11 @@ payer_pubkey = payer[:public_key]
16
16
 
17
17
  # Generate a sender keypair and public key
18
18
  owner = SolanaRuby::Keypair.generate
19
- # owner = SolanaRuby::Keypair.from_private_key("2ce523e98cfd207a216a9ac4ef8b41c38c53a302af2022d2e89e1256d1b6a1d0")
19
+ # owner = SolanaRuby::Keypair.from_private_key("4b9a36383e12d13581c37a50c38a00d91ae0e80f3ce25de852ea61f499102a33")
20
20
  owner_pubkey = owner[:public_key]
21
21
  puts "owner public key: #{owner_pubkey}"
22
- puts "payer private key: #{owner[:private_key]}"
22
+ puts "owner private key: #{owner[:private_key]}"
23
+ puts "owner full private key: #{owner[:full_private_key]}"
23
24
 
24
25
  # Airdrop some lamports to the sender's account
25
26
  # lamports = 10 * 1_000_000_000
@@ -29,7 +30,7 @@ puts "payer private key: #{owner[:private_key]}"
29
30
  # sleep(10)
30
31
 
31
32
 
32
- mint_pubkey = "5xxFuuvLiB6Gz3vbaqgkjf8fvEDXowftFiL14qUSgPiM"
33
+ mint_pubkey = "InsertMintPublicKeyHere"
33
34
  program_id = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
34
35
  puts "payer public key: #{payer_pubkey}"
35
36
 
@@ -12,10 +12,13 @@ client = SolanaRuby::HttpClient.new('http://127.0.0.1:8899')
12
12
  recent_blockhash = client.get_latest_blockhash["blockhash"]
13
13
 
14
14
  # Example parameters
15
- mint_account = "5FQhi6Kq3CKDaB3bus21ZqcL7wyeZNR18otFGoDfrZXU"
16
- destination_account = "C2wY5TKnj52S4s9yRUTNqitRe5gmFokSCoppJS6t63aa"
15
+ mint_account = "2DoNkK31X9HH5MXY6pBeb3RDZ1ZDK7wgXrcvnyipXNvf"
16
+ destination_account = "DCm6PCsdRoEXzHUdHxXnJTP65gYSPK5p8h9Cui3quiQQ"
17
17
  mint_authority = SolanaRuby::Keypair.load_keypair('/Users/chinaputtaiahbellamkonda/.config/solana/id.json')
18
- amount = 1_000_000 # Amount to mint in smallest units
18
+ puts "Full private key: #{mint_authority[:full_private_key]}"
19
+ puts "Private key: #{mint_authority[:private_key]}"
20
+ puts "Public key: #{mint_authority[:public_key]}"
21
+ amount = 1_000_000_00_00 # Amount to mint in smallest units
19
22
  multi_signers = [] # If multi-signature is used, include public keys here
20
23
 
21
24
  # Create a mint transaction
@@ -13,7 +13,7 @@ client = SolanaRuby::HttpClient.new('http://127.0.0.1:8899')
13
13
  recent_blockhash = client.get_latest_blockhash["blockhash"]
14
14
 
15
15
  # Generate a sender keypair and public key
16
- fee_payer = SolanaRuby::Keypair.load_keypair('/Users/chinaputtaiahbellamkonda/.config/solana/id.json')
16
+ fee_payer = SolanaRuby::Keypair.from_private_key('e06f61b73aa625690ef97ed3704e8dc22bc835092e94cc9ae5650b516f26c91a')
17
17
  fee_payer_pubkey = fee_payer[:public_key]
18
18
  lamports = 10 * 1_000_000_000
19
19
  space = 165
@@ -24,23 +24,24 @@ puts "sender account balance: #{balance}, wait for few seconds to update the bal
24
24
 
25
25
 
26
26
  # # Generate a receiver keypair and public key
27
- keypair = SolanaRuby::Keypair.generate
27
+ keypair = SolanaRuby::Keypair.from_private_key('f7173083807e1692e844aa2ec515eca18d016fc5e4468be75be20f6093de6641')
28
28
  receiver_pubkey = keypair[:public_key]
29
29
  transfer_lamports = 1_000_000
30
- # puts "Payer's full private key: #{sender_keypair[:full_private_key]}"
31
- # # puts "Receiver's full private key: #{keypair[:full_private_key]}"
32
- # # puts "Receiver's Public Key: #{keypair[:public_key]}"
33
- mint_address = 'G4JEi3UprH2rNz6hjBfQakLSR5EHXtS5Ry8MRFTQS5wG'
34
- token_program_id = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
30
+ mint_address = 'GDAWgGT42CqgaMds81JFVoqyJ4WBvfQsHAshPggAfXCM'
31
+
32
+ senders_token_account = SolanaRuby::TransactionHelpers::TokenAccount.get_associated_token_address(mint_address, fee_payer_pubkey)
33
+ receivers_token_account = SolanaRuby::TransactionHelpers::TokenAccount.get_associated_token_address(mint_address, receiver_pubkey)
34
+ puts "senders_token_account: #{senders_token_account}"
35
+ puts "receivers_token_account: #{receivers_token_account}"
35
36
 
36
37
  # Create a new transaction
37
38
  transaction = SolanaRuby::TransactionHelper.new_spl_token_transaction(
38
- "86w17eQHEoBcHY2rTdd5q9LjJL6Rx9QE6J1C9xgGkjt",
39
+ senders_token_account,
39
40
  mint_address,
40
- receiver_pubkey,
41
+ receivers_token_account,
41
42
  fee_payer_pubkey,
42
43
  transfer_lamports,
43
- 6,
44
+ 9,
44
45
  recent_blockhash,
45
46
  []
46
47
  )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solana-ruby-web3js
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BuildSquad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-17 00:00:00.000000000 Z
11
+ date: 2025-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-client-simple
@@ -263,6 +263,7 @@ files:
263
263
  - lib/solana_ruby/web_socket_methods/signature_methods.rb
264
264
  - lib/solana_ruby/web_socket_methods/slot_methods.rb
265
265
  - transaction_testing/burn_spl_tokens.rb
266
+ - transaction_testing/close_acccount.rb
266
267
  - transaction_testing/create_account.rb
267
268
  - transaction_testing/create_spl_token_account.rb
268
269
  - transaction_testing/mint_spl_tokens.rb