Compare commits

..

2 Commits

Author SHA1 Message Date
itzelot01 edc4cdc365 ethers get DECA orbitDB CCDB module 2024-02-22 23:08:26 +00:00
itzelot01 4e0e42042a Adding gitignore 2024-02-22 20:49:50 +00:00
4 changed files with 66 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
/node_modules
/orbitdb
/receipts
/proyectsReceipts
package-lock.json
.env
.directory

30
getDB.ts Normal file
View File

@ -0,0 +1,30 @@
import { formatUnits, Contract, Address, ABI, BigNumber } from "ethers";
import { ethers} from "./node_modules/ethers/dist/ethers.min.js";
export async function getDECACCDBAddress(providerURL: string): Promise<string> {
const provider = new ethers.JsonRpcProvider(providerURL);
let contract_address: Address = "0x3556A5005D5411603e0115efD9B875FdFb3ad7E9";
let abi: ABI = [
"function symbol() view returns (string)",
"function decimals() view returns (uint)",
"function _CCDBAddress() view returns (string)"
];
// Create a contract
let contract: Contract = new Contract(contract_address, abi, provider);
try {
let ccdbadd: string = await contract._CCDBAddress();
return ccdbadd;
} catch (error) {
console.error('Error fetching CCDBAddress:', error);
return '';
}
}
//async function main() {
// let ccdbadd: string = await getDECACCDBAddress();
// console.log(ccdbadd);
//}
//
//main();

24
index.ts Normal file
View File

@ -0,0 +1,24 @@
import { getDECACCDBAddress } from './getDB.ts'
//import * as dotenv from 'dotenv';
//dotenv.config();
import { load } from "https://deno.land/std@0.217.0/dotenv/mod.ts";
async function main() {
const env = await load();
const providerUrl = env["PROVIDER_URL"];
if(providerUrl){
try {
const ccdbadd: string = await getDECACCDBAddress(providerUrl);
console.log('Greeting from contract:', ccdbadd);
} catch (error) {
console.error('Error:', error);
}
} else {
console.error("couldn't get provider from the .env")
}
}
main();

5
package.json Normal file
View File

@ -0,0 +1,5 @@
{
"dependencies": {
"ethers": "^6.11.1"
}
}