From df50ba8f93ff1d00643927b932c30c8e712dbc1b Mon Sep 17 00:00:00 2001 From: "Mar.io" <34627453+Maar-io@users.noreply.github.com> Date: Fri, 27 May 2022 10:07:23 +0200 Subject: [PATCH] Create readNativeFronAstarbase.js --- contract/example/readNativeFronAstarbase.js | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 contract/example/readNativeFronAstarbase.js diff --git a/contract/example/readNativeFronAstarbase.js b/contract/example/readNativeFronAstarbase.js new file mode 100644 index 0000000..7f1ced2 --- /dev/null +++ b/contract/example/readNativeFronAstarbase.js @@ -0,0 +1,38 @@ +const ethers = require('ethers'); +const { exit } = require('process'); +const providerRPC = { + astarPass: { + name: 'astar', + rpc: 'https://astar.api.onfinality.io/public', + chainId: 592, + tokenName: 'ASTR', + contract: '0x8E2fa5A4D4e4f0581B69aF2f8F2Ef2CF205aE8F0' + } +}; +const provider = new ethers.providers.StaticJsonRpcProvider(providerRPC.astarPass.rpc, { + chainId: providerRPC.astarPass.chainId, + name: providerRPC.astarPass.name, +}); + +const abi = [ + "function addressMap(address evmAddress) public view returns (bytes native)" +]; + +const myArgs = process.argv.slice(1); +console.log(myArgs[1]); +if (typeof myArgs[1] === 'undefined'){ + console.log("missing input evm address"); + exit(); +} +const evmAddress = myArgs[1]; + +const readNative = async () => { + console.log(`reading native address on ${providerRPC.astarPass.name} for ${evmAddress}` ); + + const contract = new ethers.Contract(providerRPC.astarPass.contract, abi, provider); + const native = await contract.addressMap(evmAddress); + console.log(native); +} + + +readNative()