Skip to content

Commit

Permalink
updated to v1.1.0 to generate v4 and v5
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehrdad Amini committed Oct 9, 2024
1 parent d73f0b8 commit 9506ca2
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 17 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/tongen.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TON Wallet Address Finder

generate custom TON wallet addresses (V5) that end with a specific suffix.
generate custom TON wallet addresses (V4R2 and V5R2) that end with a specific suffix.
### ⭐ Support the Project by giving a satr!

If you find this project helpful or interesting, please consider giving it a star! Your support is much appreciated.
Expand Down Expand Up @@ -51,13 +51,15 @@ You should now have an executable named tongen in your project directory.

> `-testnet` (optional): Use the testnet instead of the mainnet. Defaults to false.

> `-version` (optional): Wallet version 4 or 5 (V4R2 or V5R2). Defaults to 5 (V5R2).

## Examples:
```bash
# Generate a wallet non-bouncable address that ends with "_Neo" (case-sensitive) using all CPU cores on the mainnet
./tongen -suffix="_Neo" -case-sensitive=true -bounce=false -threads=0 -testnet=false
# Generate a wallet-v4 non-bouncable address that ends with "_Neo" (case-sensitive) using all CPU cores on the mainnet
./tongen -suffix="_Xx" -case-sensitive=true -bounce=false -threads=0 -testnet=false -version=4
# Generate a wallet bouncable address that ends with "_Test" (not case-insensitive) using 4 threads on testnet
./tongen -suffix="_Test" -case-sensitive=false -bounce=true -threads=4 -testnet=false
# Generate a wallet-v5 bouncable address that ends with "_Test" (not case-insensitive) using 4 threads on testnet
./tongen -suffix="_Test" -case-sensitive=false -bounce=true -threads=4 -testnet=false -version=5
```

Expand Down
Binary file modified build/tongen
100644 → 100755
Binary file not shown.
Binary file renamed build/tongen.exe → build/tongen-x64.exe
100644 → 100755
Binary file not shown.
Binary file added build/tongen-x86.exe
Binary file not shown.
58 changes: 46 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

// Input parameters
type Config struct {
Version int
Suffix string
CaseSensitive bool
Bounce bool
Expand Down Expand Up @@ -61,19 +62,21 @@ func main() {

// parseFlags handles command-line input parameters
func parseFlags() Config {
version := flag.Int("version", 5, "Wallet version (4 or 5, default: 5)")
suffix := flag.String("suffix", "", "Desired contract address suffix (required)")
caseSensitive := flag.Bool("case-sensitive", false, "Enable case-sensitive suffix matching (default: false)")
bounce := flag.Bool("bounce", false, "Enable bounceable address (default: false)")
threads := flag.Int("threads", 0, "Number of parallel threads (default: 0, meaning use all CPU cores)")
testnet := flag.Bool("testnet", false, "Use testnet (default: false)")
flag.Parse()

if *suffix == "" {
if *suffix == "" || (*version != 4 && *version != 5) {
flag.PrintDefaults()
os.Exit(1)
}

return Config{
Version: *version,
Suffix: *suffix,
CaseSensitive: *caseSensitive,
Bounce: *bounce,
Expand All @@ -92,21 +95,21 @@ func processWallets(config Config, counter *uint64, stopChan chan struct{}, once
// Generate the seed phrase
seed := wallet.NewSeed()

// Create a V5R1Final wallet using the seed
w, err := wallet.FromSeed(nil, seed, wallet.ConfigV5R1Final{
NetworkGlobalID: getNetworkID(config.Testnet),
Workchain: 0, // Base workchain
})
// Create a wallet based on the selected version (V4 or V5)
var addressStr string
var err error

if config.Version == 5 {
addressStr, err = generateV5Wallet(seed, config)
} else {
addressStr, err = generateV4Wallet(seed, config)
}

if err != nil {
log.Printf("Failed to create wallet: %v", err)
continue
}

// Get the wallet address
addr := w.WalletAddress()
// Get the address string (mainnet or testnet) and check bounceable flag
addressStr := addr.Testnet(config.Testnet).Bounce(config.Bounce).String()

// Case-sensitive or case-insensitive suffix comparison
if config.CaseSensitive {
if strings.HasSuffix(addressStr, config.Suffix) {
Expand All @@ -128,6 +131,37 @@ func processWallets(config Config, counter *uint64, stopChan chan struct{}, once
}
}

// generateV5Wallet creates a V5 wallet and returns the corresponding address
func generateV5Wallet(seed []string, config Config) (string, error) {
// Create a V5R1Final wallet using the seed
w, err := wallet.FromSeed(nil, seed, wallet.ConfigV5R1Final{
NetworkGlobalID: getNetworkID(config.Testnet),
Workchain: 0, // Base workchain
})
if err != nil {
return "", err
}

// Get the wallet address
addr := w.WalletAddress()
addressStr := addr.Testnet(config.Testnet).Bounce(config.Bounce).String()
return addressStr, nil
}

// generateV4Wallet creates a V4 wallet and returns the corresponding address
func generateV4Wallet(seed []string, config Config) (string, error) {
// Create a V4R2 wallet using the seed
w, err := wallet.FromSeed(nil, seed, wallet.V4R2)
if err != nil {
return "", err
}

// Get the wallet address
addr := w.WalletAddress()
addressStr := addr.Testnet(config.Testnet).Bounce(config.Bounce).String()
return addressStr, nil
}

// logProgress logs how many wallets were processed in the last second
func logProgress(counter *uint64, stopChan chan struct{}) {
var lastCount uint64
Expand All @@ -144,7 +178,7 @@ func logProgress(counter *uint64, stopChan chan struct{}) {
}
}

// getNetworkID returns the correct network ID for mainnet or testnet
// getNetworkID returns the correct network ID for mainnet or testnet (only for V5)
func getNetworkID(isTestnet bool) int32 {
if isTestnet {
return -3 // Testnet Global ID
Expand Down

0 comments on commit 9506ca2

Please sign in to comment.