Last active
March 31, 2022 22:34
-
-
Save janewang/da68454ba30c40929743542f31cb2997 to your computer and use it in GitHub Desktop.
Pool details
This file contains hidden or 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 nearAPI = require('near-api-js') | |
const { keyStores, KeyPair, connect } = nearAPI; | |
const keyStore = new keyStores.InMemoryKeyStore(); | |
// const PRIVATE_KEY = | |
// "by8kdJoJHu7uUkKfoaLd2J2Dp1q1TigeWMG123pHdu9UREqPcshCM223kWadm"; | |
// // creates a public / private key pair using the provided private key | |
// const keyPair = KeyPair.fromString(PRIVATE_KEY); | |
// // adds the keyPair you created to keyStore | |
// await keyStore.setKey("testnet", "example-account.testnet", keyPair); | |
// create config | |
const config = { | |
networkId: "mainnet", | |
keyStore: keyStore, | |
nodeUrl: "https://rpc.mainnet.near.org", | |
walletUrl: "https://wallet.mainnet.near.org", | |
helperUrl: "https://helper.mainnet.near.org", | |
explorerUrl: "https://explorer.mainnet.near.org", | |
}; | |
async function routes(fastify, options) { | |
fastify.get('/pool', async (request, reply) => { | |
// connect to NEAR | |
const near = await connect(config); | |
// get account | |
const account = await near.account("name.near"); | |
// get contract | |
const contract = new nearAPI.Contract( | |
account, // the account object that is connecting | |
"name.near", | |
{ | |
// name of contract you're connecting to | |
viewMethods: [], // view methods do not change state but usually return a value | |
changeMethods: [], // change methods modify state | |
sender: account, // account object to initialize and sign transactions. | |
} | |
); | |
// pool details | |
const response = await account.viewFunction('name.near', 'get_fields_by_pool', {'pool_id': 'zavodil.poolv1.near'}) | |
return { response } | |
}) | |
} | |
module.exports = routes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
maybe this code is not needed (but don't really know), because you're using the contract as an account and calling the viewFunction, instead of loading the contract and operating with it
operating with the contract: