Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 603a943

Browse files
Add spl-token address command (#1484)
1 parent d336b8b commit 603a943

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

token/cli/src/main.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,21 @@ fn command_accounts(config: &Config, token: Option<Pubkey>) -> CommandResult {
962962
Ok(None)
963963
}
964964

965+
fn command_address(config: &Config, token: Option<Pubkey>) -> CommandResult {
966+
if let Some(token) = token {
967+
let mint = config.rpc_client.get_account(&token);
968+
if mint.is_err() || Mint::unpack(&mint.unwrap().data).is_err() {
969+
return Err(format!("Invalid mint account {:?}", token).into());
970+
}
971+
let associated_token_address = get_associated_token_address(&config.owner, &token);
972+
println!("Wallet address: {:?}", config.owner);
973+
println!("Associated token address: {:?}", associated_token_address);
974+
} else {
975+
println!("Wallet address: {:?}", config.owner);
976+
}
977+
Ok(None)
978+
}
979+
965980
fn command_account_info(config: &Config, address: Pubkey) -> CommandResult {
966981
let account = config.rpc_client.get_token_account(&address)?.unwrap();
967982
println!();
@@ -1674,6 +1689,19 @@ fn main() {
16741689
.help("Limit results to the given token. [Default: list accounts for all tokens]"),
16751690
),
16761691
)
1692+
.subcommand(
1693+
SubCommand::with_name("address")
1694+
.about("Get wallet address")
1695+
.arg(
1696+
Arg::with_name("token")
1697+
.validator(is_valid_pubkey)
1698+
.value_name("TOKEN_ADDRESS")
1699+
.takes_value(true)
1700+
.long("token")
1701+
.requires("verbose")
1702+
.help("Return the associated token address for the given token. [Default: --owner address]"),
1703+
),
1704+
)
16771705
.subcommand(
16781706
SubCommand::with_name("account-info")
16791707
.about("Query details of an SPL Token account by address")
@@ -1738,6 +1766,7 @@ fn main() {
17381766
// Owner doesn't sign when using a mulitisig...
17391767
let owner = if matches.is_present(MULTISIG_SIGNER_ARG.name)
17401768
|| sub_command == "accounts" // when calling the `accounts` command...
1769+
|| sub_command == "address" // when calling the `address` command...
17411770
|| (sub_command == "create-account" // or when creating an associated token account.
17421771
&& !matches.is_present("account_keypair"))
17431772
{
@@ -2067,6 +2096,10 @@ fn main() {
20672096
let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager).unwrap();
20682097
command_accounts(&config, token)
20692098
}
2099+
("address", Some(arg_matches)) => {
2100+
let token = pubkey_of_signer(arg_matches, "token", &mut wallet_manager).unwrap();
2101+
command_address(&config, token)
2102+
}
20702103
("account-info", Some(arg_matches)) => {
20712104
let address = pubkey_of_signer(arg_matches, "address", &mut wallet_manager)
20722105
.unwrap()

0 commit comments

Comments
 (0)