Quickstart
This page gets the protocol running on your machine: the code of the token suite and of the identity layer, built and tested, and a first test of your own against a complete local suite. It assumes you know Solidity and Foundry. It does not deploy anything on a public network.
What you need
Building and testing. Both repositories are Foundry projects, with Solidity 0.8.30 and the cancun EVM version.
Git
Cloning the repositories. Dependencies are fetched with Soldeer, which ships with Foundry.
Node.js and npm
Optional. The package.json scripts wrap the Foundry commands and install the Git hooks.
The two repositories
@t-rex-network/t-rex
The token suite: Token, TREXRegistry, IdentityRegistryStorage, ModularCompliance and its modules, TREXFactory, TREXImplementationAuthority, TREXAccessManager, the cross-chain endpoint and UtilityChecker.
@t-rex-network/onchainid
The identity layer: Identity, IdentityFactory, ERC734Validator, KeyApprovalModule, RecoveryModule, ReputationRegistry, EASClaimIssuer.
Version 5 of T-REX and version 3 of ONCHAINID are on the develop branch of each repository. T-REX pulls ONCHAINID in as a dependency, so the T-REX repository alone is enough to run a complete suite.
Build and test T-REX
git clone https://github.com/T-REX-Network/T-REX.git
cd T-REX
git checkout develop
forge soldeer install # fetch the dependencies
forge build # compile
forge test # run the testsThe build uses the IR pipeline of the compiler, which keeps ModularCompliance under the contract size limit. A full build takes minutes, not seconds.
The same commands through npm, with a few more:
npm run build
forge build
npm test
forge test --gas-report
npm run test:core
The tests without the fuzz suites and the tests of the mocks
npm run coverage
A coverage summary in the terminal
npm run format
forge fmt --check
What is in the repository
contracts/
The contracts. ERC-3643/ holds the standard interfaces and bases, the other folders the T-REX implementation: token/, registry/, compliance/, factory/, proxy/, interop/, utils/, libraries/.
test/
Foundry tests: unit/, integration/, fuzz/, invariant/ and standard/.
scripts/
Deployment scripts for the compliance modules and for UtilityChecker.
certora/
The specifications for formal verification.
mutation/
The configuration of the mutation tests.
docs/
Design notes, including the guide for module authors.
A first test against a local suite
The integration tests share a base contract, TREXSuiteTest, in test/integration/helpers/TREXSuiteTest.sol. Its setUp deploys everything a suite needs, in one test environment:
an access manager, with the test contract as its administrator;
the identity layer:
IdentityFactory, the key and claim registry module, the execution queue module, the reputation registry and the identity implementation;the implementations of the suite, the
TREXImplementationAuthorityand theTREXFactory;one token, available as
token, deployed through the factory with no required claim topic and no compliance module;an account that holds every agent role,
agent, and an account that holds the owner and manager roles,deployer;three holders with an ONCHAINID each,
alice,bobandcharlie, registered for the token, and an address with no identity,another.
The token is paused and has no supply, as after any deployment.
Create test/Quickstart.t.sol:
Run it:
What the two tests show:
The transfer to
bobsucceeds.bobresolves to an identity, and this token requires no claim, so the identity is eligible. No compliance module is bound, so every amount is allowed.The transfer to
anotherreverts withUnverifiedIdentity. The address resolves to no identity. The token refuses the recipient before anything moves. This is the eligibility gate, described in Eligibility and compliance: the two gates.
Going further with the helpers
_deployToken(salt, name, symbol)
Another token, through the factory, with its roles wired.
_deployTokenWithClaimTopic(salt, name, symbol)
A token that requires the claim topic CLAIM_TOPIC_1.
_deployTokenWithClaimedHolders(salt, name, symbol)
The same, with alice, bob and charlie registered and holding a claim from claimIssuer.
_deployIdentity(wallet, salt)
An ONCHAINID for a wallet.
_addClaim(identity, topic, data, signerKey, issuer, caller)
A signed claim added to an identity.
_removeClaim(identity, topic, caller)
The removal of that claim, to see a holder stop being eligible.
InteropSuiteTest, in the same folder, extends the suite with the cross-chain setup. The tests under test/integration/ are the best examples of every operation documented in the Guides.
Build and test ONCHAINID
Access required. The
RecoveryModulewraps a contract from OpenZeppelin'sopenzeppelin-accountsrepository, which is private.forge soldeer installclones it, so building the ONCHAINID repository requires read access to that repository and an authenticated Git. Building the T-REX repository does not.
Use the contracts in your own project
Both packages ship the Solidity sources in contracts/ and the compiled artifacts, ABI and bytecode, in out/, one JSON file per contract.
The T-REX sources import ONCHAINID under the prefix @onchain-id/solidity/ and OpenZeppelin under @openzeppelin/contracts/ and @openzeppelin/contracts-upgradeable/, version 5.7.0. A project that compiles them maps these three prefixes to the installed packages in its remappings.
An application that only reads and calls deployed contracts needs the ABIs from out/, and no remapping.
Where to go next
Understand what the tests above exercised
Deploy an asset on a network
Integrate a wallet or a custody platform
See every operation and its checks