Promise based namebase.io API wrapper
npm install namebasejs --save
This wrapper covers up to 90% of the visible endpoints on namebase currently. Submit an issue or PR to fill in the ones I'm missing.
You can get your session from the network tab of Inspect Element under namebase-main
. Copy everything after the =
. Although, you don't need to instantiate namebasejs
with a session, you can also use the local login which will store the session from your login in _auth_session
which can be gotten from the api namebasejs.session
at any time.
NOTE: Currently NameBase is returning auth0
headers to prevent you from using their API too frequently.
1.2.0
- Added handling for auth0
headers, this can be disabled if it's not working correctly or you want to handle everything yourself. You can read more about auth0
headers here.
Disable auth0
like so(after instantiation of namebasejs
): namebasejs.auth0 = false;
This doesn't stop you from using the API, it just doesn't handle the auth0
headers for you. It will still keep track of the auth0
headers and are available at namebasejs.auth0_headers
.
import NameBaseJS from "namebasejs";
const namebasejs = new NameBaseJS();
namebasejs.auth.login('email', 'password')
.then(({ data, status, headers, session }) => {
// This is the only function that returns 'session'
console.log('My current session: ', session);
if (status === 200) {
console.log('Logged in successfully!');
namebasejs.user.self().then(({ data }) => {
console.log('Current HNS Balance: ', data.hns_balance / 1000000); // convert little to big
});
}
})
.catch(console.error);
import NameBaseJS from "namebasejs";
const namebasejs = new NameBaseJS({session: 'SESSION_TOKEN'});
namebasejs.user.self().then(({ data }) => {
console.log('Current HNS Balance: ', data.hns_balance / 1000000); // convert little to big
});
import NameBaseJS from "namebasejs";
const namebasejs = new NameBaseJS({
aKey: '1dXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', // 64 Character Access Key
sKey: 'a2XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' // 64 Character Secret Key
});
// API Keys will restrict the endpoints available to you.
// It only allows the endpoints of:
// - Account
// - Marketplace
// - Trade
// - DNS
// - Ticker
// - a few Domain endpoints
namebasejs.account.self().then(({ data }) => {
const assetHNS = data.balances.find(b => b.asset === 'HNS');
console.log('Current HNS Balance: ', assetHNS.unlocked);
console.log('Order Locked HNS Balance: ', assetHNS.lockedInOrders);
});
- Clone repository:
https://github.com/ImSeaWorld/namebasejs.git
npm install
npm run test
We're now using Axios! This means we can now be used in the browser and NodeJS! Referring to the Axios documentation, the response schema is as follows:
{
data: {}, // The response that was provided by the API
status: 200, // HTTP status code from the server response
statusText: 'OK', // HTTP status message from the server response
headers: {}, // The headers that the server responded with
config: {}, // The config that was provided to `axios` for the request
request: {} // The request that generated this response
}
All methods return AxiosPromise
, the example above is how EVERY method is returned.
Any parameter with a ?
should be considered optional.
namebasejs({ session?: string, aKey?: string, sKey?: string })
- Constructornamebasejs.axios
- The instance ofaxios
used for requests.namebasejs.auth0
- Boolean to enable/disableauth0
headers. Default:true
namebasejs.auth0_headers
- Theauth0
object populated by the headers that are returned from the server. This does includenow()
function to get the current time(unix).namebasejs.receive_window
- The receive window for timed requests. Default:10000
(ms)namebasejs.enums
- The enums used for the API.namebasejs.session
- The session token used for requests. Default:null
namebasejs.auth_key
- The access key used for requests. Set with colon delimited access and secret key! Default:null
namebasejs.request(_interface, method, paylod?, ...args?)
- The request method used for all requests. This is the method that handles theauth0
headers. This method is not meant to be used directly, but is exposed for advanced usage.namebasejs.timedRequest(_interface, method, payload?, ...args?)
- The timed request method used for all requests that require areceive_window
. This method is not meant to be used directly, but is exposed for advanced usage.namebasejs.account
- The account interface.namebasejs.auction
- The auction interface.namebasejs.auth
- The auth interface.namebasejs.dns
- The dns interface.namebasejs.domain
-1.2.0
The domain interface.namebasejs.domains
- The domains interface.namebasejs.fiat
- The fiat interface.namebasejs.marketplace
- The marketplace interface.namebasejs.ticker
- The ticker interface.namebasejs.trade
- The trade interface.namebasejs.user
- The user interface.
account.self()
- Get current accountaccount.limits()
- Account limitations set by NameBaseaccount.log(accountName?, limit?)
- No idea what this isaccount.depositAddress({ asset?, timestamp?, receiveWindow? })
account.depositHistory({ asset?, startTime, endTime, timestamp?, receiveWindow? })
account.withdraw({ asset?, address, amount, timestamp?, receiveWindow? })
account.withdrawHistory({ asset?, startTime, endTime, timestamp?, receiveWindow? })
auction.bid(domain, bidAmount, blindAmount)
- Bid on a domain
auth.login(email, password, token?)
- Login using email, password and 2fa token if enabledauth.logout()
- Logout of current sessionauth.apiKeys()
- Get all API Keysauth.apiKeyCreate(name)
- Create an API Keyauth.apiKeyDelete(accessKey)
- Delete an API Key
dns.get(domain)
dns.set(domain, records)
dns.advanced(domain, rawNameState)
dns.nameServers(domain)
dns.setNameServers(domain, records, deleteRecords)
domain.get(domain)
-1.2.0
Get domain infodomain.watch(domain)
-1.2.0
Watch a domain for updates(toggles)domain.giftSLD(domain, recipientEmail, senderName, note)
-1.2.0
Gift a domain to a frienddomain.giftTLD(domain, recipientEmail, senderName, note)
-1.2.0
Gift a domain to a friend
domains.popular(offset?)
domains.recentlyWon(offset?)
domains.endingSoon(offset?)
domains.sold(offset?, sortKey?, sortDirection?)
domains.marketplace(offset?, sortKey?, sortDirection?, onlyPuny?, onlyIdnaPuny?, onlyAlternativePuny?, ...moreArgs?)
fiat.accounts()
fiat.transfers()
marketplace.list(domain, amount, description, asset?)
- List a domain for salemarketplace.domain(domain)
- Get marketplace listingmarketplace.history(domain)
- Get marketplace historymarketplace.offer(domain, buyOfferAmount)
-1.1.3
Make an offer on a domainmarketplace.cancelListing(domain)
marketplace.buyNow(domain)
ticker.day(symbol?)
ticker.book(symbol?)
ticker.price(symbol?)
ticker.supply(asset?)
ticker.klines(symbol?, interval?, startTime?, endTime?, limit?)
trade.history(symbol?, limit?)
trade.account()
trade.depth(symbol?, limit?)
trade.orders(symbol?, orderId, limit?)
trade.getOrder(symbol?, orderId)
trade.newOrder(symbol?, side, type, quantity, price)
trade.deleteOrder(symbol?, orderId)
trade.openOrders(symbol?)
user.self()
- Get current useruser.wallet()
-1.1.2
user.domainSummary()
-1.1.2
Domain summary dashboard widgetuser.messages()
-1.1.2
user.referralStats(limit?)
-1.1.2
Referral stats dashboard widgetuser.pendingHistory()
- Pending history dashboard widgetuser.domains(offset?, sortKey?, sortDirection?, limit?)
- Unlisted domainsuser.transferredDomains(offset?, sortKey?, sortDirection?, limit?)
- Domain transfer historyuser.listedDomains(offset?, limit?)
- Domains listed for saleuser.mfa()
- Check if multifactor authentication is enableduser.offersSent(offset?, sortKey?, sortDirection?)
user.offersReceived(offset?, sortKey?, sortDirection?)
user.offersNotifications()
- Offer notification widgetuser.openBids(offset?)
- Open bids on active auctionsuser.lostBids(offset?)
- Lost bids on ended auctionsuser.revealingBids(offset?)
- Bids that are currently in reveal