Set Sore
To set the Score you need to follow the next steps:
- Get transaction value
- Get nonce;
- Get Score data from Nomis API;
- Execute setScore function in the contract with the data API response.
- Confirm transaction.
Transaction Value
Value of the transaction may be 0 if the account is whitelisted. Or it may seted individually (ex. for contest winners) for the account or it may be the default value.
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 calculationModel = 11;
const id = 9999999999999n;
const publicClient = createPublicClient({
chain: polygon,
transport: http(),
});
const contract = getContract({
abi,
address: "0x4724F4B3936B4c2d52f8F452719870c5d4c86b4D",
client: publicClient,
});
const getValue = async (address: Address) => {
try {
// if account is whitelisted both mint and update fees are 0
const isWhitelisted = await contract.read.whitelist([
address,
calculationModel,
]);
if (isWhitelisted) return 0n;
const [score] = await contract.read.getScore([
address,
chainId,
calculationModel,
]);
// update
if (score !== 0) {
const individual = await contract.read.getIndividualUpdateFee([
address,
calculationModel,
]);
if (individual !== 0n) return individual;
return await contract.read.getUpdateFee();
}
// mint
const individual = await contract.read.getIndividualMintFee([
address,
calculationModel,
]);
if (individual !== 0n) return individual;
return await contract.read.getMintFee();
} catch (error) {
console.error(error);
}
};
console.log(await getValue("0x..."));
Nonce
Nonce is a number that is used to prevent replay attacks
const getNonce = async (address: Address) => {
return await contract.read.getNonce([address]);
};
console.log(await getNonce("0x..."));
Score Data
To get the Score data you need to call the Nomis Wallet Stats API with the wallet’s address and other configurations.
Score | Chain | Stats API slug | Model | Id |
---|---|---|---|---|
Astar zkEVM | Astar zkEVM | astar-zkevm | 11 (Common V3) | 3776 |
Berachain Artio Testnet | Berachain Artio | berachain | 11 (Common V3) | 80085 |
Blast | Blast | blast | 11 (Common V3) | 81457 |
Blast Sepolia Testnet | Blast Sepolia | blast-sepolia | 11 (Common V3) | 81457 |
Core | Core Dao | kroma | 11 (Common V3) | 1116 |
Cronos | Cronos Mainnet | cronos | 11 (Common V3) | 25 |
Cross-Chain DeFi | OP Mainnet | rubic | 5 (Rubic) | 22202022 |
Energi | Energi | energi | 11 (Common V3) | 39797 |
Enuls | Enuls | enuls | 11 (Common V3) | 119 |
EYWA | Polygon | eywa | 21 (Eywa) | 137 |
Gnosis | Gnosis | gnosis | 11 (Common V3) | 100 |
Kroma | Kroma | kroma | 11 (Common V3) | 255 |
LayerZero | Arbitrum One | layerzero | 12 (LayerZero) | 11101011 |
LightLink | LightLink Phoenix Mainnet | lightlink | 11 (Common V3) | 1890 |
Linea | Linea Mainnet | linea | 14 (Linea) | 59144 |
Manta | Manta Pacific Mainnet | manta | 19 (Manta) | 169 |
Metis | Metis | metis | 11 (Common V3) | 1088 |
Mint | Mint Mainnet | sei | 11 (Common V3) | 888080688 |
Mode | Mode Mainnet | mode | 11 (Common V3) | 34443 |
Moonbeam | Moonbeam | moonbeam | 11 (Common V3) | 1284 |
Multichain | Polygon | multichain | 11 (Common V3) | 9999999999999 |
Neon EVM | Neon EVM MainNet | neon | 11 (Common V3) | 245022934 |
opBNB | opBNB | opbnb | 11 (Common V3) | 59144 |
Plume Testnet | Plume Testnet | plume | 11 (Common V3) | 161221135 |
Polygon zkEVM | Polygon zkEVM | zkevm | 11 (Common V3) | 1101 |
Scroll | Scroll | scroll | 16 (Scroll) | 534352 |
Sei | Sei Network | sei | 11 (Common V3) | 888080688 |
Taiko Katla Testnet | Taiko Katla Testnet | taiko | 11 (Common V3) | 167008 |
Web3 Social | Cyber | web3social | 22 (Web3 Social) | 888080688 |
ZetaChain Testnet | ZetaChain Athens Testnet | zetchain | 11 (Common V3) | 7001 |
ZKFair | ZKFair Mainnet | zkfair | 11 (Common V3) | 42766 |
zkLink Nova | zkLink Nova | zklinknova | 11 (Common V3) | 810180 |
zkSync | ZKsync Era | zksyncera | 11 (Common V3) | 324 |
const getScoreData = async (address: string) => {
try {
const searchParams = new SearchParams({
nonce: await getNonce(address),
deadline: Date.now() + 1000 * 60 * 60 * 24, // time given to the user to sign the transaction
calculationModel,
chainId,
});
const res = await fetch(
`https://api.nomis.com/api/v1/${apiSlug}/wallet/${address}/score?${searchParams.toString()}`
);
const data = await res.json();
return { score: data.score, ...mintData };
} catch (error) {
console.error(error);
}
};
You will get an mintData object in the response:
type MintData = {
signature: string;
mintedScore: number;
calculationModel: number;
deadline: number;
metadataUrl: string;
chainId: number;
referralCode: string;
referrerCode: string;
onftMetadataUrl: string;
mintedChain: {...};
};
Transaction
To set the Score you need to call the setScore function in the contract with the data API response.
const scoreData = {...} // data from the API response
const setScore = async (address: Address) => {
try {
const scoreData = getScoreData(address);
const trx = contract.write.setScore([
scoreData.signature,
scoreData.score,
scoreData.calculationModel,
scoreData.deadline,
scoreData.metadataUrl,
scoreData.chainId,
scoreData.referralCode,
scoreData.referrerCode
])
} catch (error) {
console.error(error)
}
}