-
Notifications
You must be signed in to change notification settings - Fork 26
/
autoexecute-example.js
52 lines (43 loc) · 2.27 KB
/
autoexecute-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//NOTE: Please create a .env file in the root directory of your project. Add environment-specific variables on new lines in the form of NAME=VALUE.
//Run: secure-env .env -s mySecretPassword
//You will then get a .env.enc file created in your project root directory. You can delete the .env file after this to prevent stealing.
//pass in the password of the .env.enc file in OverledgerSDK and copy the .env.enc file to this folder
//
//NOTE: replace @quantnetwork/ with ../../packages/ for all require statements below if you have built the SDK yourself
const OverledgerSDK = require('@quantnetwork/overledger-bundle').default;
const DltNameOptions = require('@quantnetwork/overledger-types').DltNameOptions;
(async () => {
try {
const overledger = new OverledgerSDK({
dlts: [{ dlt: DltNameOptions.BITCOIN },
{ dlt: DltNameOptions.ETHEREUM },
{ dlt: DltNameOptions.XRP_LEDGER }],
userPoolID: 'us-east-1_xfjNg5Nv9', //your userpool id
provider: { network: 'https://api.sandbox.overledger.io/v2' },
envFilePassword: 'password',
});
//get required token
const refreshTokensResponse = await overledger.getTokensUsingClientIdAndSecret(
process.env.USER_NAME,
process.env.PASSWORD,
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
);
console.log('accessToken:\n', refreshTokensResponse.accessToken);
console.log('refreshToken:\n', refreshTokensResponse.refreshToken);
console.log('idToken:\n', refreshTokensResponse.idToken);
//setup overledger preparation request
const overledgerRequest = {
"location": {
"technology": "Ethereum",
"network": "Ropsten Testnet"
}
};
const overledgerInstance = overledger.provider.createRequest(refreshTokensResponse.accessToken.toString());
//send overledger preparation request
const overledgerResponse = await overledgerInstance.post("/autoexecution/search/address/balance/0x650A87cfB9165C9F4Ccc7B971D971f50f753e761",overledgerRequest);
console.log("\n\nOverledgerResponse: " + JSON.stringify(overledgerResponse.data));
} catch (e) {
console.error('error', e);
}
})();