Smart contracts
Get Score
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 | Stats API slug | Model | Id |
|---|---|---|---|---|
| Loading... |
Example
Here is an example for the Multichain Score on the Polygon chain:
import type { Address } from "viem";
import { 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..."));import type { BigNumberish } from "ethers";
import { ethers } from "ethers";
import { abi } from "./abi";
type Score = [
score: BigNumberish,
timestamp: BigNumberish,
tokenId: BigNumberish,
id: BigNumberish,
model: BigNumberish,
address: string,
];
const model = 11;
const id = 9999999999999n;
const provider = new JsonRpcProvider("https://..."); // needs to only read so you don't need a signer
const contract = new Contract(
"0x4724F4B3936B4c2d52f8F452719870c5d4c86b4D",
abi,
provider,
);
const getValue = async (address: Address) => {
try {
const [score, timestamp, tokenId] = (await contract.getScore(
address,
id,
model,
)) as Score;
return score / 100;
} catch (error) {
console.error(error);
}
};
console.log(await getScore("0x..."));