ethers get DECA orbitDB CCDB module
This commit is contained in:
parent
4e0e42042a
commit
edc4cdc365
|
@ -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();
|
|
@ -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();
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"ethers": "^6.11.1"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue