recheck-nft-library
v0.0.21
Published
Typescript library for NFT and connection with the blockchain
Downloads
39
Maintainers
Readme
recheck-nft-library
Exported functions
All functions are async. The default network is Ethereum.
In the library the usage of the chains is trough their Chain id: Currently supported for the nft retrieval : 1 - ethMainNet; 137 - polygonMain; 80001 - polygonTest;
Usage
npm i recheck-nft-library
import nftLib from 'recheck-nft-library'
let result = await nftLib.getMetadata(tokenContract, tokenID, network, owner)
API
connectAccount()
Asks which accounts to connect via Metamask
@returns an array with connected accounts
getBalance(account)
async func
@param {*} address account's address
@returns the balance of the account
getProviderMetamask()
async function
connects to Metamask, if the user has installed wallet
@returns the provider (and lets the user to get into metamask )
listAccounts()
Returns an array of accounts, public addresses, typically it should be only 1 account
@returns [ acc ]
signMessage(message)
@param {*} message the message that have to be signed by the account
@returns
switchChain(chId)
This function requires a chainID that will be the new operational chain, if the Metamask doesn't have it, a method is implemeted to add the required blockchain
@param {*} chId - the chainID that is going to be changed to
verifyMessage(message, signedMessage, signerAddress)
@param {*} message - the message that has been sent
@param {*} signedMessage - the result of the message being signed
@param {signer address} signerAddress - the public address of the signer
@returns if the signer has indeed signed this message
async function getMetadata(tokenContract, tokenID, network, owner)
This function takes contract address, nft id, network and owner of nft to traverse the blockchain and get the nft site and everything that is inside as well as the pubkey of the owner. It uses Etherscan API to find the key.
@param {String} tokenContract - smart contract blockchain address
@param {String} tokenID - NFT ID
@param {Int} network - the id of the blockchain (eth is 1)
@param {String} owner - the address of the owner
@returns JSON object with the result of the traversal - NFT metadata and owner's pub key
Example :
let tokenContract = "0xa7d8d9ef8D8Ce8992Df33D8b8CF4Aebabd5bD270"
let tokenID= "73000394"
let owner = "0x7e455CAaC23Eb8eD9884f55eD7e5A42d5DEC2bD9"
await nftLib.getMetadata(tokenContract, tokenID, 1, owner)
returns
{
statusCode: 200,
message: 'Success',
data: {
tokenURI: [ 'https://api.artblocks.io/token/73000394' ],
owner: '0x7e455CAaC23Eb8eD9884f55eD7e5A42d5DEC2bD9',
contractAddress: '0xa7d8d9ef8D8Ce8992Df33D8b8CF4Aebabd5bD270',
nftId: '73000394',
metadataContent: {
platform: 'Art Blocks Factory',
tokenID: '73000394',
series: 'N/A',
aspect_ratio: 1,
payout_address: '0x6C093Fe8bc59e1e0cAe2Ec10F0B717D3D182056B',
name: 'CatBlocks #394',
minted: true,
artist: 'Kristy Glas',
description: 'Adorable and purrfect, these carefully bred kitties express a wide range of emotions and personalities. They live entirely on-chain and they just love receiving pets.',
script_type: 'p5js',
project_id: '73',
curation_status: 'factory',
image: 'https://media.artblocks.io/73000394.png',
generator_url: 'https://generator.artblocks.io/73000394',
animation_url: 'https://generator.artblocks.io/73000394',
royaltyInfo: [Object],
collection_name: 'CatBlocks by Kristy Glas',
website: 'https://www.kristyglas.com/',
token_hash: '0xa0d48a6320f4be4ec51767d49d864bc0bce424a32a7a9c8d40448ca6e8e45bf7',
external_url: 'https://artblocks.io/token/73000394',
features: [Object],
traits: [Array],
is_static: false,
license: 'NIFTY'
},
ownerPubKey: '0xd6c86ae5248cc58ec6b5640b5fbdb099bda4ff12de8ad89972faa2c1a11a9729180058b37170f86ba27c11caad5cbfc41cadaa7aa21583e46bace00dc20aaba6'
}
async function getPubKeyFromTxHash(hash, network)
Takes tx hash, where the pubkey's owner is sender and retrieves the pubkey from the tx.
@param {String} hash - tx hash where pubkey's owner is sender
@param {String} network - url for the blockchain Ex. https://mainnet.infura.io/v3/{ID}
@returns String pubKey
async function getTxHashFromOwner(userAddress)
Retrieves tx hash where the user is sender.
@param {String} userAddress - the user address who's tx hash you are searching
@returns tx hash