Moralis Web3API.token
getTokenMetadata
返回给定代币合约地址(异步)的元数据(名称、符号、小数、徽标)。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
address
(必需):获取元数据的地址或地址数组
你可以使用JS
、React
、curl
、Unity
来实现
//Get metadata for one token. Ex: USDT token on ETH
const options = {
chain: "eth",
addresses: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
};
const tokenMetadata = await Moralis.Web3API.token.getTokenMetadata(options);
//Get metadata for an array of tokens. Ex: USDT and USDC tokens on BSC
const options = {
chain: "bsc",
addresses: [
"0x55d398326f99059ff775485246999027b3197955",
"0x0a385f86059e0b2a048171d78afd1f38558121f3",
],
};
const tokenMetadata = await Moralis.Web3API.token.getTokenMetadata(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchTokenMetadata = async () => {
//Get metadata for one token. Ex: USDT token on ETH
const options = {
chain: "eth",
addresses: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
};
const tokenMetadata = await Web3Api.token.getTokenMetadata(options);
console.log(tokenMetadata);
//Get metadata for an array of tokens. Ex: USDT and USDC tokens on BSC
const options = {
chain: "bsc",
addresses: [
"0x55d398326f99059ff775485246999027b3197955",
"0x0a385f86059e0b2a048171d78afd1f38558121f3",
],
};
const tokenArrayMetadata = await Web3Api.token.getTokenMetadata(options);
console.log(tokenArrayMetadata);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/erc20/metadata?chain=bsc&addresses=0x55d398326f99059ff775485246999027b3197955&addresses=0x0a385f86059e0b2a048171d78afd1f38558121f3' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchTokenMetadata()
{
List<string> addresses = new List<string>();
addresses.Add("0xdAC17F958D2ee523a2206206994597C13D831ec7");
addresses.Add("0x0a385f86059e0b2a048171d78afd1f38558121f3");
List<Erc20Metadata> resp = await web3Api.Token.GetTokenMetadata(addresses, ChainList.eth);
foreach(Erc20Metadata erc20metadata in resp){
print(erc20metadata.ToJson());
}
}
示例结果:
[
{
address: "0x0a385f86059e0b2a048171d78afd1f38558121f3",
name: "USD Coin on BSC",
symbol: "USDC",
logo: null,
logo_hash: null,
thumbnail: null,
decimals: "6",
block_number: "8242108",
validated: 1,
created_at: "2022-01-20T10:41:03.034Z",
},
{
address: "0x55d398326f99059ff775485246999027b3197955",
name: "Tether USD",
symbol: "USDT",
logo: null,
logo_hash: null,
thumbnail: null,
decimals: "18",
block_number: "8242108",
validated: 1,
created_at: "2022-01-20T10:41:03.034Z",
},
];
getTokenMetadataBySymbol
返回给定符号(异步)的元数据(名称、地址、小数、徽标)。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
symbols
(必需):要获取元数据的令牌符号或符号数组
你可以使用JS
、React
、curl
、Unity
来实现
//Get metadata for one token
const options = { chain: "bsc", symbols: "LINK" };
const tokenMetadata = await Moralis.Web3API.token.getTokenMetadataBySymbol(
options
);
//Get metadata for an array of tokens
const options = { chain: "bsc", symbols: ["LINK", "AAVE"] };
const tokenMetadata = await Moralis.Web3API.token.getTokenMetadataBySymbol(
options
);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchTokenMetadataBySymbol = async () => {
//Get metadata for one token
const options = { chain: "bsc", symbols: "LINK" };
const tokenMetadata = await Web3Api.token.getTokenMetadataBySymbol(options);
console.log(tokenMetadata);
//Get metadata for an array of tokens
const options = { chain: "bsc", symbols: ["LINK", "AAVE"] };
const tokenArrayMetadata = await Web3Api.token.getTokenMetadataBySymbol(
options
);
console.log(tokenArrayMetadata);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/erc20/metadata/symbols?chain=bsc&symbols=LINK&symbols=AAVE' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchTokenMetadataBySymbol()
{
List<string> symbols = new List<string>();
symbols.Add("AAVE");
symbols.Add("LINK");
List<Erc20Metadata> resp = await web3Api.Token.GetTokenMetadataBySymbol(symbols, ChainList.bsc);
foreach(Erc20Metadata erc20metadata in resp){
print(erc20metadata.ToJson());
}
}
示例结果:
[
{
address:
"0x2d30ca6f024dbc1307ac8a1a44ca27de6f797ec22ef20627a1307243b0ab7d09",
name: "Kylin Network",
symbol: "KYL",
decimals: "18",
logo: "https://img.yuanmabao.com/zijie/pic/moralis/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c.png",
logo_hash:
"ee7aa2cdf100649a3521a082116258e862e6971261a39b5cd4e4354fcccbc54d",
thumbnail:
"https://img.yuanmabao.com/zijie/pic/moralis/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c_thumb.png",
block_number: "string",
validated: "string",
},
];
getTokenAllowance
返回允许支出者从支出者提取的金额(异步)。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
owner_address
(必填):代币所有者的地址 -
spender_address
(必填):代币支出者的地址 -
address
(必填): 代币合约的地址
你可以使用JS
、React
、curl
、Unity
来实现
//Get token allowace on ETH
const options = {
//token holder
owner_address: "0xd1628228ffaede220cd583da5f9262355682210a",
//uniswap v3 router 2 contract address
spender_address: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
//ENS token contract address
address: "0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72",
};
const allowance = await Moralis.Web3API.token.getTokenAllowance(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchTokenAllowance = async () => {
//Get token allowace on ETH
const options = {
//token holder
owner_address: "0xd1628228ffaede220cd583da5f9262355682210a",
//uniswap v3 router 2 contract address
spender_address: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
//ENS token contract address
address: "0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72",
};
const allowance = await Web3Api.token.getTokenAllowance(options);
console.log(allowance);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/erc20/0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72/allowance?chain=eth&owner_address=0xd1628228ffaede220cd583da5f9262355682210a&spender_address=0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchTokenMetadataBySymbol()
{
Erc20Allowance allowance = await MoralisInterface.GetClient().Web3Api.Token.GetTokenAllowance(address: "0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72", ownerAddress: "0xd1628228ffaede220cd583da5f9262355682210a", spenderAddress: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45", ChainList.eth);
print(allowance.ToJson());
}
示例结果:
{
"allowance": "115792089237316195423570985008687907853269984665640564039457584007913129639935"
}
getTokenPrice
返回本地代币中指定的价格和给定代币合约地址的美元(异步)。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
exchange
(可选):代币交易所的工厂名称或地址。 对于不同的链,可能的交换是: -
ETH mainnet
:uniswap-v3、sushiswap、uniswap-v2 -
BSC mainnet
:pancakeswap-v2、pancakeswap-v1 -
Polygon mainnet
:快速交换。如果没有指定交换,则检查所有交换(按上面列出的顺序),直到找到有效的池。 请注意,此请求可能需要更多时间。 因此,在大多数情况下,指定交换会导致更快的响应。 -
address
(必填): 代币合约的地址 -
to_block
(可选):返回给定区块号的价格(历史价格数据)
你可以使用JS
、React
、curl
来实现
//Get token price on PancakeSwap v2 BSC
const options = {
address: "0x42F6f551ae042cBe50C739158b4f0CAC0Edb9096",
chain: "bsc",
exchange: "PancakeSwapv2",
};
const price = await Moralis.Web3API.token.getTokenPrice(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchTokenPrice = async () => {
//Get token price on PancakeSwap v2 BSC
const options = {
address: "0x42F6f551ae042cBe50C739158b4f0CAC0Edb9096",
chain: "bsc",
exchange: "PancakeSwapv2",
};
const price = await Web3Api.token.getTokenPrice(options);
console.log(price);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/erc20/0x42F6f551ae042cBe50C739158b4f0CAC0Edb9096/price?chain=bsc&exchange=PancakeSwapv2' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
示例结果:
{
"nativePrice": {
"value": "8409770570506626",
"decimals": 18,
"name": "Ether",
"symbol": "ETH"
},
"usdPrice": 19.722370676,
"exchangeAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",
"exchangeName": "Uniswap v3"
}
getAllTokenIds
针对给定的代币合约地址(异步)返回一个包含多个 NFT 的对象和一个包含 NFT 元数据(名称、符号)的数组。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
format
(可选):token id 的格式。 可用值:十进制、十六进制。 默认值:十进制。 -
offset
(可选):偏移量。 -
limit
(可选):限制。 -
address
(必填):代币合约的地址。
你可以使用JS
、React
、curl
、Unity
来实现
const options = {
address: "0x7dE3085b3190B3a787822Ee16F23be010f5F8686",
chain: "eth",
};
const NFTs = await Moralis.Web3API.token.getAllTokenIds(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchAllTokenIds = async () => {
const options = {
address: "0x7dE3085b3190B3a787822Ee16F23be010f5F8686",
chain: "eth",
};
const NFTs = await Web3Api.token.getAllTokenIds(options);
console.log(NFTs);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/0x7dE3085b3190B3a787822Ee16F23be010f5F8686?chain=eth&format=decimal' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchAllTokenIds()
{
NftCollection nfts = await MoralisInterface.GetClient().Web3Api.Token.GetAllTokenIds(address: "0x7dE3085b3190B3a787822Ee16F23be010f5F8686" , ChainList.eth);
print(nfts.ToJson());
}
示例结果:
[
{
token_address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
token_id: "728",
amount: "1",
contract_type: "ERC721",
name: "Baby Ape Mutant Club",
symbol: "BAMC",
token_uri:
"https://gateway.moralisipfs.com/ipfs/QmajSqgxY3cWBgBeRm38vasJAcTit1kp5EwqVHxszJYgUC/728.json",
metadata:
'{\n "name": "Baby Mutant #728",\n "description": "",\n "image": "ipfs://QmPUDVLP9W1pWpCTpGvpPbMu4nVpCuu2A7M6tQovDpVDoD/728.png",\n "dna": "172bef0b78106072e4eacb26db57ae70fb17b37b",\n "edition": 728,\n "date": 1645023568505,\n "artist": "Skurvydogg",\n "attributes": [\n {\n "trait_type": "BackGrounds",\n "value": "Putrid_Purple"\n },\n {\n "trait_type": "Furs",\n "value": "Red_rum"\n },\n {\n "trait_type": "Eyes",\n "value": "Robot_M1"\n },\n {\n "trait_type": "Hats",\n "value": "Bunny_Ears_M2"\n },\n {\n "trait_type": "Mouths",\n "value": "Xenomorf_M1"\n }\n ]\n}',
synced_at: "2022-03-05T02:29:18.441Z",
},
];
getNFTMetadata
返回给定合约(异步)的合约级别元数据(名称、符号、基本令牌 uri)。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
address
(必填):代币合约的地址。
你可以使用JS
、React
、curl
、Unity
来实现
对尚未索引的合约地址的请求将自动启动该
NFT
集合的索引过程
示例结果:
{
"token_address": "0x7de3085b3190b3a787822ee16f23be010f5f8686",
"name": "Baby Ape Mutant Club",
"symbol": "BAMC",
"contract_type": "ERC721",
"synced_at": "2022-02-19"
}
getNFTOwners
返回具有多个 NFT
所有者的对象和具有给定代币合约地址(异步)的 NFT
元数据(名称、符号)的数组。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
format
(可选):token id 的格式。 可用值:十进制、十六进制。 默认值:十进制。 -
offset
(可选):偏移量。 -
limit
(可选):限制。 -
address
(必填): 合约地址
你可以使用JS
、React
、curl
、Unity
来实现
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
chain: "eth",
};
const nftOwners = await Moralis.Web3API.token.getNFTOwners(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchNFTOwners = async () => {
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
chain: "eth",
};
const nftOwners = await Web3Api.token.getNFTOwners(options);
console.log(nftOwners);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/0x7de3085b3190b3a787822ee16f23be010f5f8686/owners?chain=eth&format=decimal' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchNFTOwners()
{
NftOwnerCollection nftowners = await MoralisInterface.GetClient().Web3Api.Token.GetNFTOwners(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", ChainList.eth);
print(nftowners.ToJson());
}
确保在
token_id
之类的列上包含排序参数,以获得一致的分页结果
对尚未索引的合约地址的请求将自动启动该
NFT
集合的索引过程
示例结果:
[
{
token_address: "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
token_id: "15",
contract_type: "ERC721",
owner_of: "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
block_number: "88256",
block_number_minted: "88256",
token_uri: "string",
metadata: "string",
synced_at: "string",
amount: "1",
name: "CryptoKitties",
symbol: "RARI",
},
];
searchNFTs
非常强大且快速的工具,用于基于元数据搜索(异步)获取 NFT 数据。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
format
(可选):token id 的格式。 可用值:十进制、十六进制。 默认值:十进制。 -
offset
(可选):偏移量。 -
limit
(可选):限制。 -
q
(必需):搜索字符串参数 -
filter
(必需):搜索应匹配的字段。 要查看整个元数据,请将值设置为全局。 要获得更好的响应时间,您可以查看特定字段,例如名称。 可用值:name; description; attributes; global; name,description; name,attributes; description,attributes; name,description,attributes
你可以使用JS
、React
、curl
、Unity
来实现
const options = { q: "Pancake", chain: "bsc", filter: "name" };
const NFTs = await Moralis.Web3API.token.searchNFTs(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchSearchNFTs = async () => {
const options = { q: "Pancake", chain: "bsc", filter: "name" };
const NFTs = await Web3Api.token.searchNFTs(options);
console.log(NFTs);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/search?chain=bsc&format=decimal&q=Pancake&filter=name' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchSearchNFTs()
{
NftMetadataCollection nft = await MoralisInterface.GetClient().Web3Api.Token.SearchNFTs(q: "Pancake", ChainList.bsc, filter: "name");
print(nft.ToJson());
}
示例结果:
[
{
token_id: "124436",
token_address: "0x3afa102b264b5f79ce80fed29e0724f922ba57c7",
token_uri:
"https://ipfs.moralis.io:2053/ipfs/QmVAD8v4s2SXF8FgjePqMdQ2GV5hE2isZnzxcrA36XcSDA/metadata.json",
metadata:
'{"name":"Pancake","description":"The dessert series 1","image":"ipfs://QmNQFXCZ6LGzvpMW9Q5PWbCrEnLknQrPwr2r8pbQAgzQ9A/4863BD6B-6C92-4B96-BF80-8020B2F7C3A5.jpeg"}',
contract_type: "ERC721",
token_hash: "d03fe436e972bf9215d7bb8c64c4c556",
synced_at: null,
created_at: "2021-09-19T10:36:16.610Z",
},
];
全局搜索
const options = { q: "bored ape", chain: "bsc", filter: "global" };
const NFTs = await Moralis.Web3API.token.searchNFTs(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchSearchNFTs = async () => {
const options = { q: "bored ape", chain: "bsc", filter: "global" };
const NFTs = await Web3Api.token.searchNFTs(options);
console.log(NFTs);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/search?chain=bsc&format=decimal&q=Pancake&filter=global' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchSearchNFTs()
{
NftMetadataCollection nft = await MoralisInterface.GetClient().Web3Api.Token.SearchNFTs(q: "Pancake", ChainList.bsc, filter: "global");
print(nft.ToJson());
}
按描述、属性搜索
const options = {
q: "loves bananas",
chain: "bsc",
filter: "description,attributes",
};
const NFTs = await Moralis.Web3API.token.searchNFTs(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchSearchNFTs = async () => {
const options = {
q: "loves bananas",
chain: "bsc",
filter: "description,attributes",
};
const NFTs = await Web3Api.token.searchNFTs(options);
console.log(NFTs);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/search?chain=bsc&format=decimal&q=Pancake&filter=description%2Cattributes' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchSearchNFTs()
{
NftMetadataCollection nft = await MoralisInterface.GetClient().Web3Api.Token.SearchNFTs(q: "Pancake", ChainList.bsc, filter: "description,attributes");
print(nft.ToJson());
}
getContractNFTTransfers
针对给定的代币合约地址(异步)返回一个包含 NFT 传输数量的对象和一个包含 NFT 传输的数组。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
format
(可选):token id 的格式。 可用值:十进制、十六进制。 默认值为十进制。 -
offset
(可选):偏移量。 -
limit
(可选):限制。 -
address
(必填): 合约地址
你可以使用JS
、React
、curl
、Unity
来实现
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
chain: "eth",
};
const nftTransfers = await Moralis.Web3API.token.getContractNFTTransfers(
options
);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchContractNFTTransfers = async () => {
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
chain: "eth",
};
const nftTransfers = await Web3Api.token.getContractNFTTransfers(options);
console.log(NFTs);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/0x7de3085b3190b3a787822ee16f23be010f5f8686/1/transfers?chain=eth&format=decimal' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchContractNFTTransfers()
{
NftTransferCollection nftTransers = await MoralisInterface.GetClient().Web3Api.Token.GetContractNFTTransfers(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", ChainList.eth);
print(nftTransfers.ToJson());
}
示例结果:
[
{
block_number: "14238158",
block_timestamp: "2022-02-19T18:49:02.000Z",
block_hash:
"0x8124f4a126996d306a90fa00b871b6ed9669a1a9806106b34fa28f3de61e5f8b",
transaction_hash:
"0x2db36892fc17bf99a3f6dd8a639f3c704f772858f3961cbcd26b3a42a2cd561e",
transaction_index: 162,
log_index: 419,
value: "0",
contract_type: "ERC721",
transaction_type: "Single",
token_address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
token_id: "1",
from_address: "0x0000000000000000000000000000000000000000",
to_address: "0x324fb4a58674758e00c3a49409b815de1398bfe8",
amount: "1",
verified: 1,
operator: null,
},
];
getTokenIdMetadata
返回数据,包括给定合约地址的给定令牌 id 的完全解析的元数据(异步)。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
format
(可选):token id 的格式。 可用值:十进制、十六进制。 默认值为十进制。 -
address
(必填): 合约地址 -
token_id
(必填):token 的 id
你可以使用JS
、React
、curl
、Unity
来实现
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
token_id: "1",
chain: "eth",
};
const tokenIdMetadata = await Moralis.Web3API.token.getTokenIdMetadata(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchTokenIdMetadata = async () => {
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
token_id: "1",
chain: "eth",
};
const tokenIdMetadata = await Web3Api.token.getTokenIdMetadata(options);
console.log(tokenIdMetadata);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/0x7de3085b3190b3a787822ee16f23be010f5f8686/1?chain=eth&format=decimal' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchTokenIdMetadata()
{
Nft tokenIdMetadata = await MoralisInterface.GetClient().Web3Api.Token.GetTokenIdMetadata(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", tokenId: "1", ChainList.eth);
print(tokenIdMetadata.ToJson());
}
示例结果:
{
"token_address": "0x7de3085b3190b3a787822ee16f23be010f5f8686",
"token_id": "1",
"block_number_minted": "14238158",
"owner_of": "0x324fb4a58674758e00c3a49409b815de1398bfe8",
"block_number": "14238158",
"amount": "1",
"contract_type": "ERC721",
"name": "Baby Ape Mutant Club",
"symbol": "BAMC",
"token_uri": "https://ipfs.moralis.io:2053/ipfs/QmYuHVS98nZxzYmuk9E6HA1TNr2W6PpV4fvE4MDfCFgfCP",
"metadata": "{\n \"name\": \"Baby Ape Mutant Club\",\n \"description\": \"Wait for reveal\",\n \"image\": \"ipfs://QmPS5CMBd9Zwidies964iHb9hcdDmXZkWBGZyaJ9c1Gmif\"\n}\n",
"synced_at": "2022-02-19T18:50:43.217Z",
"is_valid": 1,
"syncing": 2,
"frozen": 0
}
getTokenIdOwners
返回一个包含 NFT
传输次数的对象和一个包含给定合约集合中所有 NFT
项目所有者的数组(异步)。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
format
(可选):token id 的格式。 可用值:十进制、十六进制。 默认值为十进制 -
offset
(可选):偏移量。 -
limit
(可选):限制。 -
address
(必填):合约地址。 -
token_id
(必填):token的id。
你可以使用JS
、React
、curl
、Unity
来实现
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
token_id: "1",
chain: "eth",
};
const tokenIdOwners = await Moralis.Web3API.token.getTokenIdOwners(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchTokenIdOwners = async () => {
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
token_id: "1",
chain: "eth",
};
const tokenIdOwners = await Web3Api.token.getTokenIdOwners(options);
console.log(tokenIdOwners);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/0x7de3085b3190b3a787822ee16f23be010f5f8686/1/owners?chain=eth&format=decimal' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchTokenIdOwners()
{
NftOwnerCollection tokenIdOwners = await MoralisInterface.GetClient().Web3Api.Token.GetTokenIdOwners(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", tokenId: "1" , ChainList.eth);
print(tokenIdOwners.ToJson());
}
示例结果
[
{
token_address: "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
token_id: "15",
contract_type: "ERC721",
owner_of: "0x057Ec652A4F150f7FF94f089A38008f49a0DF88e",
block_number: "88256",
block_number_minted: "88256",
token_uri: "string",
metadata: "string",
synced_at: "string",
amount: "1",
name: "CryptoKitties",
symbol: "RARI",
},
];
getWalletTokenIdTransfers
返回一个包含 NFT
传输次数的对象和一个包含所有 NFT
传输的数组(按令牌 ID(异步))。
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
format
(可选):token id 的格式。 可用值:十进制、十六进制。 默认值为十进制 -
offset
(可选):偏移量。 -
limit
(可选):限制。 -
address
(必填):合约地址。 -
token_id
(必填):token的id。
你可以使用JS
、React
、curl
、Unity
来实现
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
token_id: "1",
chain: "eth",
};
const transfers = await Moralis.Web3API.token.getWalletTokenIdTransfers(
options
);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchWalletTokenIdTransfers = async () => {
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
token_id: "1",
chain: "eth",
};
const transfers = await Web3Api.token.getWalletTokenIdTransfers(options);
console.log(transfers);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/0x7de3085b3190b3a787822ee16f23be010f5f8686/1/transfers?chain=eth&format=decimal' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchWalletTokenIdTransfers()
{
NftTransferCollection transfers = await MoralisInterface.GetClient().Web3Api.Token.GetWalletTokenIdTransfers(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", tokenId: "1", ChainList.eth);
print(transfers.ToJson());
}
示例结果:
[
{
block_number: "14238158",
block_timestamp: "2022-02-19T18:49:02.000Z",
block_hash:
"0x8124f4a126996d306a90fa00b871b6ed9669a1a9806106b34fa28f3de61e5f8b",
transaction_hash:
"0x2db36892fc17bf99a3f6dd8a639f3c704f772858f3961cbcd26b3a42a2cd561e",
transaction_index: 162,
log_index: 419,
value: "0",
contract_type: "ERC721",
transaction_type: "Single",
token_address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
token_id: "1",
from_address: "0x0000000000000000000000000000000000000000",
to_address: "0x324fb4a58674758e00c3a49409b815de1398bfe8",
amount: "1",
verified: 1,
operator: null,
},
];
getNFTTrades
返回给定合约和市场的 NFT 交易对象
选项:
-
chain
(可选):从中获取数据的区块链。有效值列在支持的链上。默认值 Eth。 -
from_date
(可选):获取交易的日期(momentjs 接受的任何格式)。提供参数 'from_block' 或 'from_date' 如果提供了 'from_date' 和 'from_block',则将使用 'from_block'。 -
to_date
(可选):获取到此日期的交易(momentjs 接受的任何格式)。提供参数 'to_block' 或 'to_date' 如果提供了 'to_date' 和 'to_block',将使用 'to_block'。 -
from_block
(可选):从哪里获得交易的最小区块号提供参数'from_block'或'from_date'如果提供'from_date'和'from_block',将使用'from_block'。 -
to_block
(可选):获取交易的最大区块数。提供参数 'to_block' 或 'to_date' 如果提供了 'to_date' 和 'to_block',将使用 'to_block'。 -
offset
(可选):偏移量。 -
limit
(可选):限制。 -
marketplace
(可选):获取交易的市场(目前仅支持 opensea)。 -
address
(必填):合约地址(即 0x1a2b3x...)。
你可以使用JS
、React
、curl
、Unity
来实现
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
limit: "10",
chain: "eth",
};
const NFTTrades = await Moralis.Web3API.token.getNFTTrades(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchNFTTrades = async () => {
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
limit: "10",
chain: "eth",
};
const NFTTrades = await Web3Api.token.getNFTTrades(options);
console.log(NFTTrades);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/0x7de3085b3190b3a787822ee16f23be010f5f8686/trades?chain=eth&marketplace=opensea' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchNFTTrades()
{
TradeCollection trades = await MoralisInterface.GetClient().Web3Api.Token.GetNFTTrades(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", ChainList.eth, limit: 10);
print(trades.ToJson());
}
示例结果:
[
{
transaction_hash:
"0x4de0bcef1450492bd5c2e7693cf644c40005868d0dcc8a7a50a80ef2efa88d1e",
transaction_index: "164",
token_ids: ["16404"],
seller_address: "0xbae90f486d751f133702655627ce599249cd26b8",
buyer_address: "0x8795e90de359c1e0bf2579646486f7f12f270d2f",
token_address: "0xdf7952b35f24acf7fc0487d01c8d5690a60dba07",
marketplace_address: "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
price: "280000000000000000",
price_token_address: null,
block_timestamp: "2021-05-09T23:00:25.000Z",
block_number: "7281522",
block_hash:
"0xe870c197b0c614e055f4de5b264bc7c69eafc93a6d0ce300309de444b2ff7e3a",
},
];
getNFTLowestPrice
返回最近 x 天的 NFT 代币合约价格最低的对象(仅以 ETH 支付的交易)
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
days
(可选):查找最低价格的天数 如果未提供,则默认为 7 天 -
marketplace
(可选):获取交易的市场(目前仅支持 opensea)。 -
address
(必填):合约地址(即 0x1a2b3x...)。
你可以使用JS
、React
、curl
、Unity
来实现
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
days: "3",
};
const NFTLowestPrice = await Moralis.Web3API.token.getNFTLowestPrice(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const fetchNFTLowestPrice = async () => {
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
days: "3",
};
const NFTLowestPrice = await Web3Api.token.getNFTLowestPrice(options);
console.log(NFTLowestPrice);
};
curl -X 'GET' \
'https://deep-index.moralis.io/api/v2/nft/0x7de3085b3190b3a787822ee16f23be010f5f8686/lowestprice?chain=eth&days=3&marketplace=opensea' \
-H 'accept: application/json' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void fetchNFTLowestPrice()
{
Trade NFTLowestPrice = await MoralisInterface.GetClient().Web3Api.Token.GetNFTLowestPrice(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", ChainList.eth, days: 2);
print(NFTLowestPrice.ToJson());
}
示例结果:
[
{
transaction_hash:
"0xda5f3337eb74b56e99aebb5d9ebfc1e82b1c0aacc3b9b7cc606d4112ba12801d",
transaction_index: "168",
token_ids: ["254"],
seller_address: "0x8a04cea099e2d2886aea08e33446b5a52b9cf900",
buyer_address: "0xcf806faa913b3ac7bcb7b57b1199411a76d96646",
token_address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
marketplace_address: "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
price: "0",
block_timestamp: "2022-02-26T17:19:23.000Z",
block_number: "14283046",
block_hash:
"0x997713ef27375f735f7017824958c0f0093236fe7515f8759bead1ce21d554fb",
},
];
reSyncMetadata
重新同步给定 token_id
的元数据
选项:
-
chain
(可选):从中获取数据的区块链。 有效值列在支持的链上。 默认值 Eth。 -
address
(必填):合约地址。 -
token_id
(必填):token的id。 -
flag
(可选):要操作的重新同步的类型。 可用值:uri、metadata。 默认值:metadata。 metadata标志将重新同步 nft 的metadata。 uri 标志将重新同步 NFT 的 token_uri。
你可以使用JS
、React
、curl
、Unity
来实现
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
token_id: "1",
flag: "metadata",
};
const NFTLowestPrice = await Moralis.Web3API.token.reSyncMetadata(options);
import React from "react";
import { useMoralisWeb3Api } from "react-moralis";
const Web3Api = useMoralisWeb3Api();
const reSyncMetadata = async () => {
const options = {
address: "0x7de3085b3190b3a787822ee16f23be010f5f8686",
token_id: "1",
flag: "metadata",
};
const result = await Web3Api.token.reSyncMetadata(options);
console.log(result);
};
curl -X 'PUT' \
'https://deep-index.moralis.io/api/v2/nft/0x7de3085b3190b3a787822ee16f23be010f5f8686/sync?chain=eth' \
-H 'accept: */*' \
-H 'X-API-Key: MY-API-KEY'
using System.Collections.Generic;
using Moralis.Web3Api.Models;
using MoralisWeb3ApiSdk;
public async void resyncMetadata()
{
await MoralisInterface.GetClient().Web3Api.Token.ReSyncMetadata(address: "0x7de3085b3190b3a787822ee16f23be010f5f8686", tokenId: "1", chain: ChainList.eth);
}
示例结果:
{
status: "Request initiated";
}