Requesting SLP Balances
experimental (not available in production yet)
In Bitcoin Cash SLP tokens are categorized in two groups of fungible and non-fungible tokens....Using Signup you can request for the overall SLP balances a user has. The request should be accepted by the user to allow your application to access the data.
signup.requestAccess(["slp_address", "slp_balances"])
.then(({slpAddr, slpBalances}) => {
// User approved!
console.log(slpAddr, slpBalances);
});
This command will return the SLP address of the user and their SLP balances to your application. You can use user's SLP address to identify or login the user or send tokens to them. This promise will return the slpAddr and slpBalances similar to this payload:
{
slpAddr: String<slp address>,
slpBalances: [{
tokenId: String<txid>,
ticker: String,
name: String,
value: Number,
decimals: Number,
documentUri: String,
type: String<"Token", "NFT-Child", "NFT-Group">,
nftParentId: String<txid>, // will be available only for NFT-Child type
}]
}
You can use Signup's utility functions to process these data for easier consumption. For example you can only get the fungible tokens like:
const { onlyTokens } = signup.utility;
const tokens = onlyTokens(slpBalances);
Or similarly onlye NFT children:
const { onlyChildNFTs } = signup.utility;
const nfts = onlyChildNFTs(slpBalances);
You can also get the list of NFTs categorized under their Group:
const { NFTsByGroup } = signup.utility;
const nfts = NFTsByGroup(slpBalances);
console.log(nfts);
// [{
// groupName: String,
// groupId: String,
// documentUri: String,
// initialQuantity: Number,
// batonExist: Boolean,
// tokens: [{
// tokenId: String<txid>,
// ticker: String,
// name: String,
// value: Number,
// decimals: Number,
// documentUri: String,
// }]
// }]
Last modified 2yr ago