Get wallet address information
Esta página aún no está disponible en tu idioma.
For a client to request a grant from an authorization server, the client must first verify the validity of the wallet address and get the URL of the wallet’s authorization server.
These code snippets enable an authenticated client to verify a wallet address, get the basic information required to construct a new transaction, and discover the auth server’s URL. Note that unauthenticated clients can also call the Wallet Address API to get wallet address information.
Before you begin
Section titled “Before you begin”We recommend creating a wallet account on the test wallet. Creating an account allows you to test your client against the Open Payments APIs by using an ILP-enabled wallet funded with play money.
Retrieve public information for a wallet address
Section titled “Retrieve public information for a wallet address”// Import dependenciesimport { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize clientconst client = await createAuthenticatedClient({ walletAddressUrl: WALLET_ADDRESS, privateKey: PRIVATE_KEY_PATH, keyId: KEY_ID})
// Get wallet addressconst walletAddress = await client.walletAddress.get({ url: WALLET_ADDRESS})
// Outputconsole.log('WALLET ADDRESS:', walletAddress)For TypeScript, run tsx path/to/directory/index.ts. View full TS source
For JavaScript, run node path/to/directory/index.js. View full JS source
// Import dependenciesuse open_payments::client::api::UnauthenticatedResources;use open_payments::snippets::utils::{create_unauthenticated_client, get_env_var, load_env};
// Initialize clientlet client = create_unauthenticated_client();
// Get wallet addresslet wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?;let wallet_address = client.wallet_address().get(&wallet_address_url).await?;
// Outputprintln!("Retrieved wallet address: {wallet_address:#?}");// Import dependenciesuse OpenPayments\AuthClient;use OpenPayments\Config\Config;
// Initialize client$config = new Config($WALLET_ADDRESS);$opClient = new AuthClient($config); // because of missing keys in config, this will be an unauthenticated client
// Get wallet address$wallet = $opClient->walletAddress()->get(['url' => $config->getWalletAddressUrl()]);
// Outputecho 'WALLET ADDRESS: ' . PHP_EOL . print_r($wallet, true);package main
// Import dependenciesimport ("context""encoding/json""fmt""log"
op "github.com/interledger/open-payments-go")func main() {// Initialize clientclient, err := op.NewAuthenticatedClient(WALLET_ADDRESS_URL, PRIVATE_KEY_BASE_64, KEY_ID)if err != nil {log.Fatalf("Error creating authenticated client: %v\n", err)}
// Get wallet addresswalletAddress, err := client.WalletAddress.Get(context.TODO(), op.WalletAddressGetParams{URL: WALLET_ADDRESS_URL,})if err != nil {log.Fatalf("Error fetching wallet address: %v\n", err)}
// OutputwalletAddressJSON, err := json.MarshalIndent(walletAddress, "", " ")if err != nil {log.Fatalf("Error marshaling wallet address: %v\n", err)}fmt.Println("WALLET ADDRESS:", string(walletAddressJSON))}// Import dependenciesimport org.interledger.openpayments.httpclient.OpenPaymentsHttpClient;import org.interledger.openpayments.IOpenPaymentsClient;
// Initialize clientvar client = OpenPaymentsHttpClient.defaultClient("WalletAddress","PrivateKeyPEM","KeyId");
// Get wallet addressvar walletAddress = client.getWalletAddress("https://cloudninebank.example.com/customer");
// Outputlog.info("WALLET_ADDRESS: {}", walletAddress);