The following script will scan all the active loans of a user.
You will need NODE.js and the web3 module installed in your device.
Save the script in a file with extension js
. E.g.: loans.js
.
Then you can execute it in your console as:
$ node loans
In the same folder that you store this file you will need the ABI of the LoanMaintenance
contract, in a file called ABI_Maintenance.json
, in JSON format.
Also you will need a JSON file called user.json
. The only parameter you will need to configure in user.json
is the address. Put there the user´s address for who you're looking for the loan Id's.
You can find the ABI file here. And an example for the user file here.
The output will be shown on your screen but also will be stored in the new file userLoans
.
const fs = require('fs');
const Web3 = require('web3');
// const url = 'https://mainnet2.sovryn.app';
const url = 'https://public-node.rsk.co';
const web3 = new Web3(url);
var ABI = fs.readFileSync('./ABI_Maintenance.json', 'utf8');
ABI = JSON.parse(ABI);
var USER = fs.readFileSync('./user.json', 'utf8');
USER = JSON.parse(USER);
var user = USER.addrs;
user = user.toLowerCase();
var Proxy = '0x5a0D867E0D70FCc6ADe25c3f1B89d618b5B4EaA7';
Proxy = Proxy.toLowerCase();
const Maintein = new web3.eth.Contract(ABI, Proxy);
var listen = web3.eth.net.isListening().then(console.log);
async function giveUserData() {
await Maintein.methods.getUserLoans(user, 0, 10, 0, false, false).call(function(err, userData){
console.log(userData);
var file = './userLoans';
var objecString = JSON.stringify(userData);
fs.writeFileSync(file, objecString);
});
}
giveUserData();
If the user has a large quantity of positions, in the method getUserLoans(user, 0, 10, 0, false, false)
you can change the number "10
" for a larger number.