Since 2009, we have been utilizing our extensive expertise in blockchain technologies to help businesses, both large and small, maximize their efficiency.
Explore More
With more than 400+ experts, Oodles comprises a fantastic resource of business knowledge that spans multiple industries. Whatever the circumstances, we keep to our obligations.
Explore More
At Oodles, we help our clients work with a human understanding but at superhuman speed something that others can't. They thus advance and maintain their lead
28th June 2022
9 min read
Senior Associate Consultant - Development
The javascript code shared below will check for links between 2 addresses. There are 3 types of links that the program will check for i.e. direct, layer 1 & layer 2 which are explained below.
Direct link: If Alice and Bob have a transaction with each other.
Alice -> Bob
Layer 1 link: If Alice and Bob have not transacted with each other but have transacted with a common address.
Alice -> common address -> Bob
Layer 2 link :
Alice -> random address -> random address -> Bob
Code for the link finding software -
const { getTransactedAddresses } = require("./api");
const { getUnique } = require("./removeDuplicates");
// Set addresses below for which you need to find links.
const address1 = "";
const address2 = "";
getTransactedAddresses(address1)
.then((arr) => {
try {
var layer1CommonAdd = "";
var array2 = [];
const array = getUnique(arr);
if (array.includes(address2.toLowerCase())) {
console.log("\n DIRECT LINK FOUND \n");
} else {
let flag = 0;
console.log("\n ! NO DIRECT LINK FOUND ! \n");
console.log("Searching for layer 1 link... \n");
getTransactedAddresses(address2)
.then((arr2) => {
array2 = getUnique(arr2);
array2.forEach(ele => {
if (array.includes(ele)) {
flag = 1;
layer1CommonAdd = ele;
}
})
})
.then(() => {
if (flag === 1) {
console.log("layer 1 link found\n");
console.log("Both addresses have interacted with => " + layer1CommonAdd + "\n");
} else {
console.log("Searching for layer 2 link... \n");
var counter = 0;
var i = setInterval(() => {
getTransactedAddresses(array[counter])
.then((arr3) => {
const array3 = getUnique(arr3);
array3.forEach(ele => {
if (array2.includes(ele)) {
console.log("layer 2 link found\n");
console.log(address1 + "\n =>\n" + array[counter - 1] + "\n =>\n" + ele + "\n =>\n" + address2 + "\n");
}
})
})
counter++;
if(counter === array.length) {
clearInterval(i);
}
}, 5000);
}
})
}
} catch (e) {
console.log(e);
}
})
You are probably wondering why I have used setInterval in the above code, that's because the APIs provided by Ethereum / Binance have rate limiters in them. A rate limiter limits the number of times one can call an API within a stipulated timeframe, hence we are limited by the APIs to find links for 2 layers at max. In the future, if they provide APIs without these rate limiters, the software could be created for finding links for many more layers. Such kind of software will definitely help us to find scammers and accounts who were culprits in the rug pools that take place.
The above code uses 2 imports which are ->
1. APIs - There are APIs available by both Ethereum and Binance, which are exactly the same. They are available for Mainnet and Testnet, so you can use ETH APIs to find links on Ethereum and BSC APIs for finding links on Binance Smart Chain.
link to BSC APIs - https://docs.bscscan.com/api-endpoints/accounts#get-a-list-of-normal-transactions-by-address
code -
const axios = require('axios');
module.exports.getTransactedAddresses = async (address) => {
try {
const response = await axios.get('https://api-testnet.bscscan.com/api', {
params: {
module: "account",
action: "txlist",
address: address,
apiKey: "please_read_the_bsc_docs_to_get_the_key",
startblock: 0,
endblock: 99999999,
sort: "asc"
}
});
const array = [];
response.data.result.forEach(i => {
if(i.to !== '' && i.to !== address.toLowerCase()) {
array.push(i.to);
}
if(i.from !== '' && i.from !== address.toLowerCase()) {
array.push(i.from);
}
});
return array;
} catch (e) {
console.error(e);
}
}
** IMP NOTE - The API will only output the first 10,000 transactions, so if an account has more than 10k you will have to change the blocks manually or could also create a new program for the automatic increments.
2. Remove Duplicates - This is just to increase the efficiency of the overall program.
code -
module.exports.getUnique = (arr) => {
let uniqueArr = [];
for(let i of arr) {
if(uniqueArr.indexOf(i) === -1) {
uniqueArr.push(i);
}
}
return uniqueArr;
}
Prajwal Arora
Prajwal is a blockchain developer having years of experience in software engineering. He is an expert in python, shell scripts, MERN stack, and more. He also has experience in building infrastructure as code templates with IaC tools like terraform and AWS
Senior Associate Consultant - Development
By using this site, you allow our use of cookies. For more information on the cookies we use and how to delete or block them, please read our cookie notice.
We would love to
hear from you!
Innovate with confidence!