ARCx
Search…
πŸ€–
Smart Contracts
Using ARCx scores to make data-driven decisions on-chain.

Using a Score in a Smart Contract

To verify a score, first fetch a Score Proof from our API*.
*Drop the metadata attribute if its included*
Second, pass your Score Proof to any smart contract to verify and use it on-chain. Here's an example on how to handle an arcx.loyalty score over 50:
1
...
2
​
3
import { ISapphirePassportScores } from "@arcxgame/contracts/contracts/sapphire/ISapphirePassportScores.sol";
4
import { SapphireTypes } from "@arcxgame/contracts/contracts/sapphire/SapphireTypes.sol";
5
​
6
...
7
​
8
contract ExampleContract {
9
​
10
...
11
12
// Address of ARCx SapphirePassportScores contract
13
ISapphirePassportScores public passportScores;
14
​
15
// Score that is required, e.g. 'arcx.loyalty' encoded into bytes32
16
bytes32 private magicProtocol = 0x617263782e6c6f79616c74790000000000000000000000000000000000000000
17
...
18
​
19
constructor(address _passportScoresAddress) {
20
passportScores = _passportScoresAddress;
21
}
22
​
23
...
24
25
function doSomeMagic(SapphireTypes.ScoreProof _scoreProof){
26
27
require (
28
_scoreProof.protocol == magicProtocol,
29
"This score is not an arcx.loyalty score!"
30
);
31
32
// Returns true if valid, reverts when invalid
33
passportScores.verify(_scoreProof);
34
35
if (_scoreProof.score > 50) {
36
// Do something magical knowing score is greater than 50!
37
}
38
}
39
40
...
41
}
Copied!
*Developer tip: Feel free to import our npm package to easily manage ABI's

How it works

*Disclaimer: Our infrastructure is still under development and is subject to change*
The ARCx infrastructure is built on Merkle trees to maintain proper security and scalability standards. For those who are new to Merkle trees/Hash trees, here's a refresher on a few important terms:
  • Merkle leaf: The leaf of a Merkle Tree. Leaves are hashed together to create a Merkle tree. In our context, each leaf represents a score and has the following format:
1
{
2
"account": "0x123...456",
3
"protocol": "0x617...000",
4
"score": "175",
5
}
Copied!
Property
Description
account
The wallet address associated with this score.
protocol
The byte32 encoded representation of the score name. This format is enforced for memory efficiency. The protocol in simply the byte32 encoded value of a score name, e.g. arcx.loyalty.
score
The quantification of this score. This must be a non-negative value within the scope of a BigNumber.
  • Merkle root: Is the combined hash of all the elements in a Merkle tree. Our contracts continuously update their roots as new scores and addresses are added.
  • Merkle proof: An array of hashes that when combined with a Merkle leaf, verifies the integrity said leaf. If combining the leaf and proof corresponds to the root published on-chain, the leaf is considered legitimate and ready for on-chain use.
​
All the scores (i.e. Merkle leaves) are combined into a Merkle tree off-chain. Then, each score and its corresponding Merkle proof is saved into our databases (soon to be IPFS). Once all the scores have been saved, we push the root of our Merkle tree on all our supported chains.
​
The Merkle root is identical on all networks.
The Contract epoch is the same on all networks.
Merkle roots are automatically delayed and analyzed before going live for security purposes. Current delay period is 24h.

Help

If you have any questions or suggestions, we'd love your input on our discord server. Happy building! γƒŽ