Last active
July 26, 2021 16:21
-
-
Save drewstaylor/9bd1d6979e47a47167b5300d8965c632 to your computer and use it in GitHub Desktop.
FA2 balance_of request in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TezosToolkit = require('@taquito/taquito') | |
const compose = require('@taquito/taquito'); | |
const tzip12 = require('@taquito/tzip12'); | |
const Tzip12Module = require('@taquito/tzip12'); | |
const tzip16 = require('@taquito/tzip16'); | |
const Tzip16Module = require('@taquito/tzip16'); | |
const importKey = require('@taquito/signer').importKey; | |
const Tezos = new TezosToolkit.TezosToolkit("https://mainnet-tezos.giganode.io"); | |
Tezos.addExtension(new Tzip12Module.Tzip12Module()); | |
Tezos.addExtension(new Tzip16Module.Tzip16Module()); | |
const FA2 = "KT1TBaU9Jz3DnZAifL9pcW4g3EvH9WpNFyo1"; | |
const TokenHolder = "tz1P7LT36ZnP2iKYSjNF2Za2Tiuj1b7EPP2G"; | |
const getFa2 = async () => { | |
return Tezos.contract.at(FA2, compose.compose(tzip16.tzip16, tzip12.tzip12)); | |
}; | |
const toJSON = (x) => JSON.parse(JSON.stringify(x)); | |
const main = async () => { | |
// Import Alice's key so you have a signer | |
await importKey(Tezos, 'edsk3QoqBuvdamxouPhin7swCvkQNgq4jP5KZPbwWNnwdZpSpJiEbq'); | |
let c = await getFa2(); | |
// Get `balance_of` | |
let a = { | |
owner: TokenHolder, | |
token_id: '2' | |
}; | |
let balance_of = await c.views.balance_of([a]).read(); | |
balance_of = toJSON(balance_of); | |
console.log('balance_of =>', balance_of); | |
}; | |
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "fa2-test", | |
"version": "1.0.0", | |
"description": "", | |
"main": "fa2.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "node balanceOf.js" | |
}, | |
"keywords": [ | |
"Tezos" | |
], | |
"author": "[email protected]", | |
"license": "MIT", | |
"dependencies": { | |
"@taquito/beacon-wallet": "^9.2.0", | |
"@taquito/signer": "^9.2.0", | |
"@taquito/taquito": "^9.2.0", | |
"@taquito/tzip12": "^9.2.0", | |
"@taquito/tzip16": "^9.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment