How to get coin metadata by coin type hashes
Prerequisitesβ
Before getting started, make sure you have the following ready:
- Node v.14+ or Python
- NPM/Yarn or Pip
Step 1: Setup Moralisβ
First register your Moralis account and get your Moralis API Key.
Once you have your Moralis API Key, install the Moralis SDK in your project.
- npm
- yarn
- pnpm
- pip
npm install moralis
yarn add moralis
pnpm add moralis
pip install moralis
Step 2: Get Coin Metadata By Coin Type Hashesβ
In order to get coin metadata by coin type hashes, Moralis provides you a getCoinsByCoinTypeHash endpoint to do so.
Here you'll need one parameter: coinTypeHashes
.
Once you have obtained the coinTypeHashes
, you can copy the following code:
- index.js (JavaScript)
- index.ts (TypeScript)
- index.py (Python)
const Moralis = require("moralis").default;
const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});
const coinTypeHashes = [
"175cc6491b0d75a131a36391318cde4c4b1312de70675c7e46cc54dacfe7ae29",
];
const response = await Moralis.AptosApi.coins.getCoinInfoByCoinTypeHashes({
coinTypeHashes,
network: "mainnet",
});
console.log(response.result);
};
runApp();
import Moralis from "moralis";
const runApp = async () => {
await Moralis.start({
apiKey: "YOUR_API_KEY",
// ...and any other configuration
});
const coinTypeHashes = [
"175cc6491b0d75a131a36391318cde4c4b1312de70675c7e46cc54dacfe7ae29",
];
const response = await Moralis.AptosApi.coins.getCoinInfoByCoinTypeHashes({
coinTypeHashes,
network: "mainnet",
});
console.log(response.result);
};
runApp();
from moralis import aptos_api
api_key = "YOUR_API_KEY"
params = {
"network": "mainnet",
"coin_type_hashes": ["175cc6491b0d75a131a36391318cde4c4b1312de70675c7e46cc54dacfe7ae29"]
}
result = aptos_api.coins.get_coins_by_coin_type_hashes(
api_key=api_key,
params=params,
)
print(result)
Step 3: Run the scriptβ
To run the script, enter the following command:
- Shell (JavaScript)
- Shell (TypeScript)
- Shell (Python)
node index.js
ts-node index.ts
python index.py
In your terminal, you should see the following JSON response:
{
[
{
"coin_type": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT",
"coin_type_hash": "175cc6491b0d75a131a36391318cde4c4b1312de70675c7e46cc54dacfe7ae29",
"name": "Tether USD",
"creator_address": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa",
"decimals": 6,
"supply_aggregator_table_handle": null,
"supply_aggregator_table_key": null,
"symbol": "USDT",
"transaction_created_timestamp": "2022-10-19T02:43:38.000Z",
"transaction_version_created": "2413215"
}
]
}
Congratulations π₯³ You just got coin metadata by coin type hashes with just a few lines of code using the Moralis Coin API!
Youtube Videoβ
API Referenceβ
If you want to know more details on the endpoint and optional parameters, check out:
Supportβ
If you face any trouble following the tutorial, feel free to reach out to our community engineers in our Discord or Forum to get 24/7 developer support.