<!DOCTYPE html><htmllang="en"><head><metacharSet="utf-8"/><metahttp-equiv="X-UA-Compatible"content="IE=edge"/><title>Wallet Get Address APIs · bitcoin-s</title><metaname="viewport"content="width=device-width"/><metaname="generator"content="Docusaurus"/><metaname="description"content="The Bitcoin-S wallet has a few different functions for getting a wallet address"/><metaname="docsearch:version"content="next"/><metaname="docsearch:language"content="en"/><metaproperty="og:title"content="Wallet Get Address APIs · bitcoin-s"/><metaproperty="og:type"content="website"/><metaproperty="og:url"content="https://bitcoin-s.org/"/><metaproperty="og:description"content="The Bitcoin-S wallet has a few different functions for getting a wallet address"/><metaproperty="og:image"content="https://bitcoin-s.org/img/undraw_online.svg"/><metaname="twitter:card"content="summary"/><metaname="twitter:image"content="https://bitcoin-s.org/img/undraw_tweetstorm.svg"/><linkrel="shortcut icon"href="/img/favicon.ico"/><linkrel="stylesheet"href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css"/><linkrel="stylesheet"href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/><script>
function createToggler(togglerSelector, targetSelector, className) {
var toggler = document.querySelector(togglerSelector);
var target = document.querySelector(targetSelector);
if (!toggler) {
return;
}
toggler.onclick = function(event) {
event.preventDefault();
target.classList.toggle(className);
};
}
});
</script></nav></div><divclass="container mainContainer docsContainer"><divclass="wrapper"><divclass="post"><headerclass="postHeader"><aclass="edit-page-link button"href="https://github.com/bitcoin-s/bitcoin-s/blob/master/docs/wallet/wallet-get-address.md"target="_blank"rel="noreferrer noopener">Edit</a><h1id="__docusaurus"class="postHeaderTitle">Wallet Get Address APIs</h1></header><article><div><span><p>The Bitcoin-S wallet has a few different functions for getting a wallet address
that all server different purposes.</p>
<p>First, there is <code>getNewAddress</code>. This function will always return a new a address
determined by the next address available address index.</p>
<p>Second, we have <code>getUnusedAddress</code>. This function will return an address that has
not ever received funds.</p>
<p>Third, there is <code>getAddress</code>. This function takes in an <code>AccountDb</code>, <code>HDChainType</code>,
and an <code>Int</code>. This will return the address associated with the pubkey at
<p>The Bitcoin-S wallet uses a background thread meant to ensure safety when fetching addresses.
This is to ensure independent calls to getNewAddress don't result in a race condition to the database that would generate the same address and cause an error.
With this background thread, we poll the <code>addressRequestQueue</code> seeing if there are any elements in it, if there are, we process them and complete the Promise in the queue.</p>
<p>There are two ways to configure the wallet's address queue.</p>
<ol>
<li><p><code>addressQueueSize</code>: How big the address queue size is before we throw an overflow exception</p></li>
<li><p><code>addressQueueTimeout</code>: How long we attempt to generate an address for before it times out</p></li>
</ol>
<p>For an example configuration, checkout the <ahref="/docs/next/config/configuration#example-configuration-file">example config</a>.</p>