Automating AML checks for all token holders in smart contracts
Part 2 of 2
Connect your smart contract to the Chainalysis API with our step-by-step Silent Data [Oracle] job configuration
![](https://d9hhrg4mnvzow.cloudfront.net/www.silentdata.com/blog/automating-aml-checks-for-all-token-holders-in-smart-contracts/77e7c4d7-68d5-4ea3-b974-0bb70bb3b55c-part-2.png)
![](https://d9hhrg4mnvzow.cloudfront.net/www.silentdata.com/blog/automating-aml-checks-for-all-token-holders-in-smart-contracts/79cb7b7f-4239-435e-9f61-16489b507c01-b369b323-9e54-4486-95f5-f88c0bea7a61-c4ab1d35-77c0-4428-92ea-3838a1013d8a-chelsea.png)
Noam Elstein
February 9, 2024
![](https://d9hhrg4mnvzow.cloudfront.net/www.silentdata.com/blog/automating-aml-checks-for-all-token-holders-in-smart-contracts/c128d474-7ba2-4446-bb63-24a488a19853-part-2-flow-chart.png)
Step 0: Set up Chainalysis
Request Chainalysis documentation for details of configuring risk assessment criteria and obtaining a secret key.
Chainalysis API Key
In order to get data from Chainalysis on-chain, we must connect to a Chainlaysis API, here an Entities API. Given the data on Chainlaysis is private, we require a private API Key to establish this connection.
Request access for the Chainalysis API documentationToken contract
function transfer(address to, uint256 value) public virtual override returns (bool) {
uint256 lastValidBlock = block.number - 100;
// AML check only valid in last 100 blocks
require(whitelistContract.getLastAMLCheckBlock(to) >= lastValidBlock, "AML check not present or not recent enough");
_transfer(_msgSender(), to, value);
return true;
}
The Token contract queries the Whitelist contract to obtain the block number for the last time the address was screened.
In this example, the AML check is only valid for the last 100 blocks.
Step 1: Configure the job and trigger
When using the smart contract trigger, the Allowed callers feature sets the allowed smart contract addresses to trigger the Oracle job. Adding allowed callers prevents other contracts from draining your funded jobs. Here only the Whitelist contract, the only allowed caller, can trigger the job.
Trigger Method (Inside the whitelist contract)
// Implement logic to call the funding contract, to emit an event that triggers a job
// Only configured allowed contracts will be able to trigger specific jobs
function requestWhitelist(address _addressToCheck) external {
require(address(fundingContract) != address(0), 'Funding contract not set');
bytes memory encodedArgs = abi.encode(_addressToCheck);
// Add logic for job triggering here
fundingContract.emitSilentDataJobTriggerArgs(jobId, encodedArgs);
}
Step 2: Configure the steps
Request #1
Method determines what kind of function you require the job to perform. This is subject to the type of API call the AML compliance service requires.
The Endpoint is an API URL i.e. the specific location of accepting requests and returning responses. The endpoint URL is unique to the AML compliance service used and may depend on the type of job you are configuring.
Request access to the Chainalysis documentation for more information regarding the Address Screening Tool API endpoint and Method.
The Header provides authorisation to the bearer of the Chainalysis API key i.e. whoever holds the secret API. The syntax for the authorisation is in a JSON call format, and as seen later in the video, must match the name of the secret you configure.
Depending on the API you call, it may be necessary to send data in the body to the API. Here we must include the address of the wallet we are registering on Chainalysis.
Attestation #1
Next, it is time to create the Rules for your call. The Source determines the variable or value of the data you want to check. Meanwhile, the Target defines what to compare your value to for a successful result. Here we are checking whether the wallet has successfully passed the screening i.e. status 200 (or 201). Otherwise the failure callback will be called.
Step 2(b): Configure Secrets
Entering your Silent Data [Oracle] password allows you to update the job configuration without re-uploading your secrets every time - secrets are only saved in the local storage of the browser.
The Silent Data [Oracle] operator never actually sees your API key! Secrets are only decrypted inside the Intel hardware secure enclave.
Step 3: Configure the result
Success
We define the value ‘address’ to inform the whitelist contract which wallet address has been screened. The value ‘true’ confirms the address has passed the risk assessment retrieved. Meanwhile, the value ‘false’ confirms the address has failed the screening test and is not added to the whitelist.
// Implement logic to be executed as the result of the SilentData Job
function silentDataCallback(address _requester, bool _amlCheckPassed) public onlyResultsContract {
if(_amlCheckPassed) {
lastWhitelisted[_requester] = block.number;
}
}
The callback contract is defined to consume the result of the AML Check. The boolean returned is either ‘true’ for a successful check or ‘false’ for a risky one.
If ‘true’ (the address has passed the check) then the address is added to the Whitelist with the corresponding block number detailed.
Step 4: Fund and publish your job
Funding configuration
Jobs are funded under Funding details. This requests a transfer from your wallet which requires approval, as seen in the video using Metamask.
In the video, as we are using the Sepolia testnet network, we must connect our Metamask wallet to Sepolia. Any faucet may be used to supply Seoplia Ethereum (ETHSepolia) - the tokens used for Sepolia testnet.
See Silent Data [Oracle] Documentation for greater detail re Configuration of Job.
Visualise the results
Chainalysis is only one AML use case for Silent Data [Oracle]. A multitude of other enterprise and DeFi use cases exist, both for triggering a job from the smart contract or webhook. Consult the resources linked throughout for greater detail.
Remember to sign up for our demo environment!
This forms part of a two-part blog, click here to read part 1!
© Copyright 2024 Applied Blockchain Ltd.
All rights reserved Applied Blockchain Ltd is a company registered in England and Wales. Company No. 09686276