Copy npm i Web3 @charged-particles/protocol-subgraph dotenv
Copy RPC_URL=YOUR_RPC_URL_FOR_KOVAN_HERE_WE_RECOMMEND_ALCHEMY_API
Copy require('dotenv').config({
path: `.env.${process.env.NODE_ENV || 'development'}`,
});
const Web3 = require('web3');
const kovanAddresses = require('@charged-particles/protocol-subgraph/networks/kovan');
const RPC_URL = process.env.RPC_URL;
const readOnlyProvider = new Web3.providers.HttpProvider(RPC_URL);
const readOnlyWeb3 = new Web3(readOnlyProvider);
// These 2 are required to be able to craft a ProtonNFT web3 read only
const protonAbi = require('@charged-particles/protocol-subgraph/abis/Proton');
const protonAddress = kovanAddresses.proton.address;
const readOnlyProtonContract = new readOnlyWeb3.eth.Contract(protonAbi, protonAddress);
const getTotalProtons = async() => {
const methodToCall = 'totalSupply';
const lastId = await readOnlyProtonContract.methods[methodToCall]().call();
console.log({protonAddress, lastId});
return lastId;
}
getTotalProtons()
.catch(err => console.error(err));
// These 2 are required to be able to craft a ChargedParticles contract web3 read only
const chargedParticlesAbi = require('@charged-particles/protocol-subgraph/abis/ChargedParticles');
const chargedParticlesAddress = kovanAddresses.chargedParticles.address;
const readOnlychargedParticlesContract = new readOnlyWeb3.eth.Contract(chargedParticlesAbi, chargedParticlesAddress);
// Signature: currentParticleCharge(address,uint256,string,address)(uint256)
const getCurrentCharge = async({tokenId, managerId, underlyingAssetAddress}) => {
// Params: https://docs.charged.fi/charged-particles-protocol/smart-contracts-documentation/contracts/smart-contracts-documentation#currentparticlecharge
const methodToCall = 'currentParticleCharge';
const args = [
protonAddress, // address contractAddress,
tokenId, // uint256 tokenId,
managerId, // string managerId,
underlyingAssetAddress, // address assetToken
];
const currentCharge = await readOnlychargedParticlesContract.methods[methodToCall](...args).call();
console.log({currentCharge});
return currentCharge;
}
// Now let's look at the charge generated on
// https://staging.charged.fi/go/energize/0xD4F7389297d9cea850777EA6ccBD7Db5817a12b2/26
// tokenId: 26
// Getting the charge of the WETH for the Proton #26
getCurrentCharge({
tokenId: 26, // https://staging.charged.fi/go/energize/0xD4F7389297d9cea850777EA6ccBD7Db5817a12b2/26
managerId: 'aave', // or 'generic' if looking for an ERC20 balance, not supported by AAVE lending
underlyingAssetAddress: '0xd0a1e359811322d97991e03f863a0c30c2cf029c' // Kovan WETH
})