Get Sore
Primitives
Every score has it’s own model and id, so you need to provide them to get the score.
Model represents the calculating model of the score, and id is the unique identifier of the score.
Score | Chain | Model | Id |
---|
Example
Here is an example for the Multichain Score on the Polygon chain:
import { type Address, createPublicClient, getContract, http } from 'viem';
import { polygon } from 'viem/chains';
import { abi } from './abi';
const model = 11;
const id = 9999999999999n;
const publicClient = createPublicClient({
chain: polygon,
transport: http(),
});
const contract = getContract({
abi,
address: '0x4724F4B3936B4c2d52f8F452719870c5d4c86b4D',
client: publicClient,
});
const getScore = async (address: Address) => {
try {
const [score, timestamp, tokenId] = await contract.read.getScore([
address,
id,
model,
]);
return score / 100;
} catch (error) {
console.error(error);
}
};
console.log(await getScore('0x...'));