diff --git a/.env b/.env new file mode 100644 index 000000000..e4677080a --- /dev/null +++ b/.env @@ -0,0 +1,18 @@ +# public Avalanche API +IP = "api.avax.network" +PORT = 443 +PROTOCOL = "https" +NETWORK_ID = 1 + +# localhost +LOCAL_IP= "127.0.0.1" +LOCAL_PORT = 9650 +LOCAL_PROTOCOL = "http" +LOCAL_NETWORK_ID = 1337 + +# index API +IP_INDEXER = "indexer-demo.avax.network" + +# socket +PROTOCOL_WS = "ws" +HOST = "localhost" diff --git a/.gitignore b/.gitignore index b078d0eac..75ec4965d 100644 --- a/.gitignore +++ b/.gitignore @@ -76,10 +76,6 @@ docsHTML/ # Yarn Integrity file .yarn-integrity -# dotenv environment variables file -.env -.env.test - # parcel-bundler cache (https://parceljs.org/) .cache diff --git a/examples/admin/alias.ts b/examples/admin/alias.ts index 8e5adc591..dc00cfbb5 100644 --- a/examples/admin/alias.ts +++ b/examples/admin/alias.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AdminAPI } from "../../src/apis/admin" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const admin: AdminAPI = avalanche.Admin() diff --git a/examples/admin/aliasChain.ts b/examples/admin/aliasChain.ts index e24be4628..e3664fcb9 100644 --- a/examples/admin/aliasChain.ts +++ b/examples/admin/aliasChain.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AdminAPI } from "../../src/apis/admin" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const admin: AdminAPI = avalanche.Admin() diff --git a/examples/admin/getChainAliases.ts b/examples/admin/getChainAliases.ts index dbf2d14a6..9b64a435c 100644 --- a/examples/admin/getChainAliases.ts +++ b/examples/admin/getChainAliases.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AdminAPI } from "../../src/apis/admin" import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const admin: AdminAPI = avalanche.Admin() diff --git a/examples/admin/getLoggerLevel.ts b/examples/admin/getLoggerLevel.ts index 96b172cf6..5c56cb653 100644 --- a/examples/admin/getLoggerLevel.ts +++ b/examples/admin/getLoggerLevel.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AdminAPI } from "../../src/apis/admin" import { GetLoggerLevelResponse } from "../../src/apis/admin/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const admin: AdminAPI = avalanche.Admin() diff --git a/examples/admin/loadVMs.ts b/examples/admin/loadVMs.ts index 28a2dd17e..82b9e24ed 100644 --- a/examples/admin/loadVMs.ts +++ b/examples/admin/loadVMs.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AdminAPI } from "../../src/apis/admin" import { LoadVMsResponse } from "../../src/apis/admin/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const admin: AdminAPI = avalanche.Admin() diff --git a/examples/admin/lockProfile.ts b/examples/admin/lockProfile.ts index 06eb960ad..0438f7bbc 100644 --- a/examples/admin/lockProfile.ts +++ b/examples/admin/lockProfile.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AdminAPI } from "../../src/apis/admin" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const admin: AdminAPI = avalanche.Admin() diff --git a/examples/admin/memoryProfile.ts b/examples/admin/memoryProfile.ts index 41707c369..eaa995ea4 100644 --- a/examples/admin/memoryProfile.ts +++ b/examples/admin/memoryProfile.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AdminAPI } from "../../src/apis/admin" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const admin: AdminAPI = avalanche.Admin() diff --git a/examples/admin/setLoggerLevel.ts b/examples/admin/setLoggerLevel.ts index 5803bb6ac..20c7d6b41 100644 --- a/examples/admin/setLoggerLevel.ts +++ b/examples/admin/setLoggerLevel.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AdminAPI } from "../../src/apis/admin" import { SetLoggerLevelResponse } from "../../src/apis/admin/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const admin: AdminAPI = avalanche.Admin() diff --git a/examples/admin/startCPUProfiler.ts b/examples/admin/startCPUProfiler.ts index 17ffab61c..7eb192ec7 100644 --- a/examples/admin/startCPUProfiler.ts +++ b/examples/admin/startCPUProfiler.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AdminAPI } from "../../src/apis/admin" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const admin: AdminAPI = avalanche.Admin() diff --git a/examples/admin/stopCPUProfiler.ts b/examples/admin/stopCPUProfiler.ts index 1abc3c0f6..71d8d984d 100644 --- a/examples/admin/stopCPUProfiler.ts +++ b/examples/admin/stopCPUProfiler.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AdminAPI } from "../../src/apis/admin" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const admin: AdminAPI = avalanche.Admin() diff --git a/examples/auth/changePassword.ts b/examples/auth/changePassword.ts index a5e15bab4..d3be6698d 100644 --- a/examples/auth/changePassword.ts +++ b/examples/auth/changePassword.ts @@ -2,14 +2,15 @@ // which you can create based on "secrets.example" which is in the // root of the `examples/` directory. // Unlike "secrets.example", "secrets.json" should never be committed to git. +import "dotenv/config" import { Avalanche } from "../../src" import { AuthAPI } from "../../src/apis/auth" import { readFile } from "fs" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const auth: AuthAPI = avalanche.Auth() diff --git a/examples/auth/newToken.ts b/examples/auth/newToken.ts index 7ae19389c..ab320225f 100644 --- a/examples/auth/newToken.ts +++ b/examples/auth/newToken.ts @@ -2,15 +2,16 @@ // which you can create based on "secrets.example" which is in the // root of the `examples/` directory. // Unlike "secrets.example", "secrets.json" should never be committed to git. +import "dotenv/config" import { readFile } from "fs" import { Avalanche } from "../../src" import { AuthAPI } from "../../src/apis/auth" import { ErrorResponseObject } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const auth: AuthAPI = avalanche.Auth() diff --git a/examples/auth/revokeToken.ts b/examples/auth/revokeToken.ts index a69c3f6b8..e8b991071 100644 --- a/examples/auth/revokeToken.ts +++ b/examples/auth/revokeToken.ts @@ -2,14 +2,15 @@ // which you can create based on "secrets.example" which is in the // root of the `examples/` directory. // Unlike "secrets.example", "secrets.json" should never be committed to git. +import "dotenv/config" import { readFile } from "fs" import { Avalanche } from "../../src" import { AuthAPI } from "../../src/apis/auth" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const auth: AuthAPI = avalanche.Auth() diff --git a/examples/avm/JSONXChainTx.ts b/examples/avm/JSONXChainTx.ts index 469243d89..ee33b2f0c 100644 --- a/examples/avm/JSONXChainTx.ts +++ b/examples/avm/JSONXChainTx.ts @@ -1,15 +1,17 @@ +import "dotenv/config" import { Avalanche, Buffer } from "../../src" import { AVMAPI, Tx } from "../../src/apis/avm" -const ip: string = "api.avax.network" -const port: number = 443 -const protocol: string = "https" -const networkID: number = 1 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) + const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const main = async (): Promise => { - const txID: string = "2fJer7o3HpPYxqyHXo23G4HoPvfEqcUXYojMULi2mbBEoBFqoM" + const txID: string = "Cgse9mcZeXrYsBGrF3SqjoDHoqxauiwxm6zrgkDa5kxSa5K85" const hex = (await xchain.getTx(txID)) as string const buf: Buffer = new Buffer(hex.slice(2), "hex") const tx: Tx = new Tx() diff --git a/examples/avm/addressFromBuffer.ts b/examples/avm/addressFromBuffer.ts index a9f62e3fc..fd2bd4dc4 100644 --- a/examples/avm/addressFromBuffer.ts +++ b/examples/avm/addressFromBuffer.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, Buffer } from "../../src" import { AVMAPI } from "../../src/apis/avm" import { UTXOSet, UTXO } from "../../src/apis/platformvm" diff --git a/examples/avm/baseEndpoint.ts b/examples/avm/baseEndpoint.ts index 1f1866b2a..ae15aea83 100644 --- a/examples/avm/baseEndpoint.ts +++ b/examples/avm/baseEndpoint.ts @@ -1,9 +1,10 @@ +import "dotenv/config" import { Avalanche } from "../../src" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const baseEndpoint: string = "rpc" const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) avalanche.setAddress(ip, port, protocol, baseEndpoint) diff --git a/examples/avm/baseTx-ant.ts b/examples/avm/baseTx-ant.ts index 41db93228..845faab5c 100644 --- a/examples/avm/baseTx-ant.ts +++ b/examples/avm/baseTx-ant.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -19,10 +20,10 @@ import { DefaultLocalGenesisPrivateKey } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/baseTx-avax-create-multisig.ts b/examples/avm/baseTx-avax-create-multisig.ts index 5696ffdcd..f8e974d03 100644 --- a/examples/avm/baseTx-avax-create-multisig.ts +++ b/examples/avm/baseTx-avax-create-multisig.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -21,10 +22,10 @@ import { } from "../../src/utils" const bintools: BinTools = BinTools.getInstance() -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const xBlockchainID: string = Defaults.network[networkID].X.blockchainID const xBlockchainIDBuf: Buffer = bintools.cb58Decode(xBlockchainID) const avaxAssetID: string = Defaults.network[networkID].X.avaxAssetID diff --git a/examples/avm/baseTx-avax-send-multisig.ts b/examples/avm/baseTx-avax-send-multisig.ts index 96b16e1f5..5523e8c85 100644 --- a/examples/avm/baseTx-avax-send-multisig.ts +++ b/examples/avm/baseTx-avax-send-multisig.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -20,10 +21,10 @@ import { } from "../../src/utils" const bintools: BinTools = BinTools.getInstance() -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const xBlockchainID: string = Defaults.network[networkID].X.blockchainID const xBlockchainIDBuf: Buffer = bintools.cb58Decode(xBlockchainID) const avaxAssetID: string = Defaults.network[networkID].X.avaxAssetID diff --git a/examples/avm/baseTx-avax.ts b/examples/avm/baseTx-avax.ts index f8293edce..cd6c2b1c0 100644 --- a/examples/avm/baseTx-avax.ts +++ b/examples/avm/baseTx-avax.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import createHash from "create-hash" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { @@ -21,10 +22,10 @@ import { } from "../../src/utils" const bintools: BinTools = BinTools.getInstance() -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const xBlockchainID: string = Defaults.network[networkID].X.blockchainID const avaxAssetID: string = Defaults.network[networkID].X.avaxAssetID diff --git a/examples/avm/buildBaseTx-ant.ts b/examples/avm/buildBaseTx-ant.ts index 9fbac92b2..1e0716a9a 100644 --- a/examples/avm/buildBaseTx-ant.ts +++ b/examples/avm/buildBaseTx-ant.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { GetUTXOsResponse } from "../../src/apis/avm/interfaces" import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, KeyChain, UTXOSet, UnsignedTx, Tx } from "../../src/apis/avm" @@ -7,10 +8,10 @@ import { DefaultLocalGenesisPrivateKey } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const xKeychain: KeyChain = xchain.keyChain() diff --git a/examples/avm/buildBaseTx-avax.ts b/examples/avm/buildBaseTx-avax.ts index 3962075bb..abd0e1d14 100644 --- a/examples/avm/buildBaseTx-avax.ts +++ b/examples/avm/buildBaseTx-avax.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, KeyChain, UTXOSet, UnsignedTx, Tx } from "../../src/apis/avm" import { @@ -11,10 +12,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const xBlockchainID: string = Defaults.network[networkID].X.blockchainID const avaxAssetID: string = Defaults.network[networkID].X.avaxAssetID const avalanche: Avalanche = new Avalanche( diff --git a/examples/avm/buildCreateAssetTx.ts b/examples/avm/buildCreateAssetTx.ts index 67904fa03..8559a31e2 100644 --- a/examples/avm/buildCreateAssetTx.ts +++ b/examples/avm/buildCreateAssetTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, @@ -15,10 +16,10 @@ import { DefaultLocalGenesisPrivateKey } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const xKeychain: KeyChain = xchain.keyChain() diff --git a/examples/avm/buildCreateNFTAssetTx.ts b/examples/avm/buildCreateNFTAssetTx.ts index 6b01a263f..b5b3339b1 100644 --- a/examples/avm/buildCreateNFTAssetTx.ts +++ b/examples/avm/buildCreateNFTAssetTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, @@ -14,10 +15,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const xKeychain: AVMKeyChain = xchain.keyChain() diff --git a/examples/avm/buildCreateNFTMintTx.ts b/examples/avm/buildCreateNFTMintTx.ts index 4c3797910..a6dc167c4 100644 --- a/examples/avm/buildCreateNFTMintTx.ts +++ b/examples/avm/buildCreateNFTMintTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -40,10 +41,10 @@ const getUTXOIDs = ( return result } -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/buildExportTx-PChain.ts b/examples/avm/buildExportTx-PChain.ts index a9a892e0d..77e10dd1c 100644 --- a/examples/avm/buildExportTx-PChain.ts +++ b/examples/avm/buildExportTx-PChain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, @@ -21,10 +22,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/avm/buildExportTx-cchain-ant.ts b/examples/avm/buildExportTx-cchain-ant.ts index 481ee8c72..78d0ddc0e 100644 --- a/examples/avm/buildExportTx-cchain-ant.ts +++ b/examples/avm/buildExportTx-cchain-ant.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, @@ -15,10 +16,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/avm/buildExportTx-cchain-avax.ts b/examples/avm/buildExportTx-cchain-avax.ts index ab3f40dda..395083a5c 100644 --- a/examples/avm/buildExportTx-cchain-avax.ts +++ b/examples/avm/buildExportTx-cchain-avax.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, @@ -18,10 +19,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/avm/buildImportTx-PChain.ts b/examples/avm/buildImportTx-PChain.ts index 0456f9f7f..5dc618388 100644 --- a/examples/avm/buildImportTx-PChain.ts +++ b/examples/avm/buildImportTx-PChain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, KeyChain, UTXOSet, UnsignedTx, Tx } from "../../src/apis/avm" import { GetUTXOsResponse } from "../../src/apis/avm/interfaces" @@ -8,10 +9,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const xKeychain: KeyChain = xchain.keyChain() diff --git a/examples/avm/buildImportTx-cchain.ts b/examples/avm/buildImportTx-cchain.ts index cb1895d5f..f72035603 100644 --- a/examples/avm/buildImportTx-cchain.ts +++ b/examples/avm/buildImportTx-cchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, KeyChain, UTXOSet, UnsignedTx, Tx } from "../../src/apis/avm" import { GetUTXOsResponse } from "../../src/apis/avm/interfaces" @@ -8,10 +9,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const xKeychain: KeyChain = xchain.keyChain() diff --git a/examples/avm/buildNFTTransferTx.ts b/examples/avm/buildNFTTransferTx.ts index e5afe4fcb..9e12af1c5 100644 --- a/examples/avm/buildNFTTransferTx.ts +++ b/examples/avm/buildNFTTransferTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -36,10 +37,10 @@ const getUTXOIDs = ( return result } -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/buildSECPMintTx.ts b/examples/avm/buildSECPMintTx.ts index 42dc48c53..b3bdf8909 100644 --- a/examples/avm/buildSECPMintTx.ts +++ b/examples/avm/buildSECPMintTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -42,10 +43,10 @@ const getUTXOIDs = ( return result } -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/createAddress.ts b/examples/avm/createAddress.ts index 51607f12a..6229f988b 100644 --- a/examples/avm/createAddress.ts +++ b/examples/avm/createAddress.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/createAssetTx-ant.ts b/examples/avm/createAssetTx-ant.ts index 0696fedc1..0c20d24e1 100644 --- a/examples/avm/createAssetTx-ant.ts +++ b/examples/avm/createAssetTx-ant.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -21,10 +22,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/createAssetTx-nft.ts b/examples/avm/createAssetTx-nft.ts index e78b9632e..e14820575 100644 --- a/examples/avm/createAssetTx-nft.ts +++ b/examples/avm/createAssetTx-nft.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -23,10 +24,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/createKeypair.ts b/examples/avm/createKeypair.ts index 6ce120b79..7f82ed587 100644 --- a/examples/avm/createKeypair.ts +++ b/examples/avm/createKeypair.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI, KeyChain, KeyPair } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/createTXID.ts b/examples/avm/createTXID.ts index 949d3de58..8eea9744e 100644 --- a/examples/avm/createTXID.ts +++ b/examples/avm/createTXID.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import createHash from "create-hash" import { Avalanche, BN, Buffer } from "../../src" import { @@ -21,10 +22,10 @@ import { import { Serialization } from "../../src/utils" const serialization: Serialization = Serialization.getInstance() -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/avm/exportTx-ant-cchain.ts b/examples/avm/exportTx-ant-cchain.ts index 79b476583..473331bcc 100644 --- a/examples/avm/exportTx-ant-cchain.ts +++ b/examples/avm/exportTx-ant-cchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -19,10 +20,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/exportTx-avax-cchain.ts b/examples/avm/exportTx-avax-cchain.ts index c996b8a49..401f60926 100644 --- a/examples/avm/exportTx-avax-cchain.ts +++ b/examples/avm/exportTx-avax-cchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -19,10 +20,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/exportTx-avax-pchain.ts b/examples/avm/exportTx-avax-pchain.ts index 63a90ddbf..75658330e 100644 --- a/examples/avm/exportTx-avax-pchain.ts +++ b/examples/avm/exportTx-avax-pchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -19,10 +20,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/exportTx-avax-to-the-pchain-and-create-a-multisig-atomic-utxo.ts b/examples/avm/exportTx-avax-to-the-pchain-and-create-a-multisig-atomic-utxo.ts index 23ef69f31..da4c5f839 100644 --- a/examples/avm/exportTx-avax-to-the-pchain-and-create-a-multisig-atomic-utxo.ts +++ b/examples/avm/exportTx-avax-to-the-pchain-and-create-a-multisig-atomic-utxo.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -23,10 +24,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/avm/genesisData.ts b/examples/avm/genesisData.ts index 2c1cd5368..073f0b173 100644 --- a/examples/avm/genesisData.ts +++ b/examples/avm/genesisData.ts @@ -1,4 +1,5 @@ -import Avalanche, { BN, Buffer } from "../../src" +import "dotenv/config" +import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, GenesisAsset, @@ -15,10 +16,10 @@ import { SerializedType } from "../../src/utils" const serialization: Serialization = Serialization.getInstance() -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const xKeychain: KeyChain = xchain.keyChain() diff --git a/examples/avm/getAVAXAssetID.ts b/examples/avm/getAVAXAssetID.ts index 477b8cbf3..c59b68aee 100644 --- a/examples/avm/getAVAXAssetID.ts +++ b/examples/avm/getAVAXAssetID.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, Buffer } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/getAllBalances.ts b/examples/avm/getAllBalances.ts index 577a044d7..709550561 100644 --- a/examples/avm/getAllBalances.ts +++ b/examples/avm/getAllBalances.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/getAssetDescription.ts b/examples/avm/getAssetDescription.ts index 5d613bb2e..18ba9d9f2 100644 --- a/examples/avm/getAssetDescription.ts +++ b/examples/avm/getAssetDescription.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/getBalance.ts b/examples/avm/getBalance.ts index a2ba6e425..d28f284c1 100644 --- a/examples/avm/getBalance.ts +++ b/examples/avm/getBalance.ts @@ -1,15 +1,16 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const main = async (): Promise => { - const address: string = "X-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p" + const address: string = "X-avax19zfygxaf59stehzedhxjesads0p5jdvfeedal0" const balance: object = await xchain.getBalance(address, "AVAX") console.log(balance) } diff --git a/examples/avm/getBlockchainAlias.ts b/examples/avm/getBlockchainAlias.ts index 2bac5f242..30c7f806d 100644 --- a/examples/avm/getBlockchainAlias.ts +++ b/examples/avm/getBlockchainAlias.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/getBlockchainID.ts b/examples/avm/getBlockchainID.ts index 31f760eb7..a3abf0ac7 100644 --- a/examples/avm/getBlockchainID.ts +++ b/examples/avm/getBlockchainID.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/getCreationTxFee.ts b/examples/avm/getCreationTxFee.ts index d35e21c92..55e5eb4a2 100644 --- a/examples/avm/getCreationTxFee.ts +++ b/examples/avm/getCreationTxFee.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/getDefaultCreationTxFee.ts b/examples/avm/getDefaultCreationTxFee.ts index 65bbe8637..033c9930f 100644 --- a/examples/avm/getDefaultCreationTxFee.ts +++ b/examples/avm/getDefaultCreationTxFee.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/getDefaultTxFee.ts b/examples/avm/getDefaultTxFee.ts index d4434c0a4..d5e952914 100644 --- a/examples/avm/getDefaultTxFee.ts +++ b/examples/avm/getDefaultTxFee.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/getTx.ts b/examples/avm/getTx.ts index c1aab4c8e..00d5b17ff 100644 --- a/examples/avm/getTx.ts +++ b/examples/avm/getTx.ts @@ -1,15 +1,16 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const main = async (): Promise => { - const txID: string = "Ycg5QzddNwe3ebfFXhoGUDnWgC6GE88QRakRnn9dp3nGwqCwD" + const txID: string = "Cgse9mcZeXrYsBGrF3SqjoDHoqxauiwxm6zrgkDa5kxSa5K85" const encoding: string = "json" const tx: string | object = await xchain.getTx(txID, encoding) console.log(tx) diff --git a/examples/avm/getTxFee.ts b/examples/avm/getTxFee.ts index f7967769a..c7d0cc7ea 100644 --- a/examples/avm/getTxFee.ts +++ b/examples/avm/getTxFee.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/getTxStatus.ts b/examples/avm/getTxStatus.ts index 56f50e7cf..54f417d3d 100644 --- a/examples/avm/getTxStatus.ts +++ b/examples/avm/getTxStatus.ts @@ -1,16 +1,17 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const main = async (): Promise => { const status: string = await xchain.getTxStatus( - "2WdpWdsqE26Qypmf66No8KeBYbNhdk3zSG7a5uNYZ3FLSvCu1D" + "2MSJdxJ64sVLQ9GUatyzjCjazrgVMCYbD1zxFHPseqY5r8Hrdp" ) console.log(status) } diff --git a/examples/avm/importTx-cchain.ts b/examples/avm/importTx-cchain.ts index 2010de8ea..768ac18bc 100644 --- a/examples/avm/importTx-cchain.ts +++ b/examples/avm/importTx-cchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -19,10 +20,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/importTx-pchain.ts b/examples/avm/importTx-pchain.ts index f61521a6c..8d704ec61 100644 --- a/examples/avm/importTx-pchain.ts +++ b/examples/avm/importTx-pchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -19,10 +20,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/keyChain.ts b/examples/avm/keyChain.ts index f90a3a252..5e42d0469 100644 --- a/examples/avm/keyChain.ts +++ b/examples/avm/keyChain.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI, KeyChain } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/listAddresses.ts b/examples/avm/listAddresses.ts index 5b9fe10f4..d36995815 100644 --- a/examples/avm/listAddresses.ts +++ b/examples/avm/listAddresses.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/newKeyChain.ts b/examples/avm/newKeyChain.ts index e4096954b..3215b03a1 100644 --- a/examples/avm/newKeyChain.ts +++ b/examples/avm/newKeyChain.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI, KeyChain } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/operationTx-mint-ant.ts b/examples/avm/operationTx-mint-ant.ts index ab2cb04ca..dfcaee7b6 100644 --- a/examples/avm/operationTx-mint-ant.ts +++ b/examples/avm/operationTx-mint-ant.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -46,10 +47,10 @@ const getUTXOIDs = ( return result } -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/operationTx-mint-nft.ts b/examples/avm/operationTx-mint-nft.ts index db213bcda..80246430b 100644 --- a/examples/avm/operationTx-mint-nft.ts +++ b/examples/avm/operationTx-mint-nft.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, @@ -47,10 +48,10 @@ const getUTXOIDs = ( return result } -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/avm/parseAddress.ts b/examples/avm/parseAddress.ts index 0f006c714..ec977b528 100644 --- a/examples/avm/parseAddress.ts +++ b/examples/avm/parseAddress.ts @@ -1,15 +1,16 @@ +import "dotenv/config" import { Avalanche, Buffer } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const main = async (): Promise => { - const addressString: string = "X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u" + const addressString: string = "X-avax19zfygxaf59stehzedhxjesads0p5jdvfeedal0" const addressBuffer: Buffer = xchain.parseAddress(addressString) console.log(addressBuffer) } diff --git a/examples/avm/refreshBlockchainID.ts b/examples/avm/refreshBlockchainID.ts index 5c6c4ee8f..bbe403038 100644 --- a/examples/avm/refreshBlockchainID.ts +++ b/examples/avm/refreshBlockchainID.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/setAVAXAssetID.ts b/examples/avm/setAVAXAssetID.ts index 019d8388c..af103dd1c 100644 --- a/examples/avm/setAVAXAssetID.ts +++ b/examples/avm/setAVAXAssetID.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, Buffer } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/setBlockchainAlias.ts b/examples/avm/setBlockchainAlias.ts index f8a844f23..0c588774f 100644 --- a/examples/avm/setBlockchainAlias.ts +++ b/examples/avm/setBlockchainAlias.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/setCreationTxFee.ts b/examples/avm/setCreationTxFee.ts index 11d832620..a8f271f9a 100644 --- a/examples/avm/setCreationTxFee.ts +++ b/examples/avm/setCreationTxFee.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/avm/setTxFee.ts b/examples/avm/setTxFee.ts index db5fa6b38..8ce2464e6 100644 --- a/examples/avm/setTxFee.ts +++ b/examples/avm/setTxFee.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { AVMAPI } from "../../src/apis/avm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() diff --git a/examples/evm/JSONCChainTx.ts b/examples/evm/JSONCChainTx.ts index 26fc0bec2..486c5018f 100644 --- a/examples/evm/JSONCChainTx.ts +++ b/examples/evm/JSONCChainTx.ts @@ -1,13 +1,15 @@ -import { Avalanche, BN, Buffer } from "../../src" +import "dotenv/config" +import { Avalanche, Buffer } from "../../src" import { EVMAPI, Tx } from "../../src/apis/evm" import { Serialization } from "../../src/utils" import { SerializedType } from "../../src/utils" import * as bech32 from "bech32" +import "dotenv/config" -const ip: string = "api.avax.network" -const port: number = 443 -const protocol: string = "https" -const networkID: number = 1 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const cchain: EVMAPI = avalanche.CChain() const cb58: SerializedType = "cb58" diff --git a/examples/evm/bech32AddressEncoder.ts b/examples/evm/bech32AddressEncoder.ts index 8bdce46eb..fac67b76d 100644 --- a/examples/evm/bech32AddressEncoder.ts +++ b/examples/evm/bech32AddressEncoder.ts @@ -1,10 +1,6 @@ import * as bech32 from "bech32" import { Buffer } from "../../src" -const fromDecToHex = (item: number) => { - const hexVal = item.toString(16) - return hexVal.length < 2 ? "0" + hexVal : hexVal -} const bech32Encoder = (item: string) => { const hrp = "avax" const bufFromHex = Buffer.from(item.slice(2), "hex") diff --git a/examples/evm/buildExportTx-pchain.ts b/examples/evm/buildExportTx-pchain.ts index 72cc5983e..0b35ff4d0 100644 --- a/examples/evm/buildExportTx-pchain.ts +++ b/examples/evm/buildExportTx-pchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { PlatformVMAPI, @@ -16,10 +17,10 @@ import { costExportTx } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/buildExportTx-xchain-ant.ts b/examples/evm/buildExportTx-xchain-ant.ts index 570971731..008212990 100644 --- a/examples/evm/buildExportTx-xchain-ant.ts +++ b/examples/evm/buildExportTx-xchain-ant.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { AVMAPI, KeyChain as AVMKeyChain } from "../../src/apis/avm" import { @@ -13,10 +14,10 @@ import { costExportTx } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/buildExportTx-xchain-avax.ts b/examples/evm/buildExportTx-xchain-avax.ts index 0f0385abb..534fd63ce 100644 --- a/examples/evm/buildExportTx-xchain-avax.ts +++ b/examples/evm/buildExportTx-xchain-avax.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { AVMAPI, KeyChain as AVMKeyChain } from "../../src/apis/avm" import { @@ -13,10 +14,10 @@ import { costExportTx } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/buildImportTx-PChain.ts b/examples/evm/buildImportTx-PChain.ts index f0ea3769a..82731fb10 100644 --- a/examples/evm/buildImportTx-PChain.ts +++ b/examples/evm/buildImportTx-PChain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { PlatformVMAPI, @@ -17,10 +18,10 @@ import { costImportTx } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/buildImportTx-xchain.ts b/examples/evm/buildImportTx-xchain.ts index df5214373..2a5089377 100644 --- a/examples/evm/buildImportTx-xchain.ts +++ b/examples/evm/buildImportTx-xchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { AVMAPI, KeyChain as AVMKeyChain } from "../../src/apis/avm" import { @@ -14,10 +15,10 @@ import { costImportTx } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/createKeypair.ts b/examples/evm/createKeypair.ts index 65cb57c07..83853cdb8 100644 --- a/examples/evm/createKeypair.ts +++ b/examples/evm/createKeypair.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { EVMAPI, KeyChain, KeyPair } from "../../src/apis/evm" import { CreateKeyPairResponse } from "../../src/apis/evm/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/exportTx-ant-xchain.ts b/examples/evm/exportTx-ant-xchain.ts index 305879941..0056ce42d 100644 --- a/examples/evm/exportTx-ant-xchain.ts +++ b/examples/evm/exportTx-ant-xchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, KeyChain as AVMKeyChain } from "../../src/apis/avm" import { @@ -17,10 +18,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/exportTx-avax-pchain-create-multisig-atomic-output.ts b/examples/evm/exportTx-avax-pchain-create-multisig-atomic-output.ts index 34558fbd3..d61f57fe8 100644 --- a/examples/evm/exportTx-avax-pchain-create-multisig-atomic-output.ts +++ b/examples/evm/exportTx-avax-pchain-create-multisig-atomic-output.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -21,10 +22,10 @@ import { } from "../../src/utils" const Web3 = require("web3") -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/exportTx-avax-xchain.ts b/examples/evm/exportTx-avax-xchain.ts index c7f22cc4f..f2461f1a6 100644 --- a/examples/evm/exportTx-avax-xchain.ts +++ b/examples/evm/exportTx-avax-xchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, KeyChain as AVMKeyChain } from "../../src/apis/avm" import { @@ -16,10 +17,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/getAssetBalance.ts b/examples/evm/getAssetBalance.ts index 2d643521a..f5dbe53b7 100644 --- a/examples/evm/getAssetBalance.ts +++ b/examples/evm/getAssetBalance.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { EVMAPI } from "../../src/apis/evm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/getAtomicTx.ts b/examples/evm/getAtomicTx.ts index 4381ca8e0..f4e18d754 100644 --- a/examples/evm/getAtomicTx.ts +++ b/examples/evm/getAtomicTx.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { EVMAPI } from "../../src/apis/evm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/getAtomicTxStatus.ts b/examples/evm/getAtomicTxStatus.ts index 3737728e2..843a09a13 100644 --- a/examples/evm/getAtomicTxStatus.ts +++ b/examples/evm/getAtomicTxStatus.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { EVMAPI } from "../../src/apis/evm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/getBaseFee.ts b/examples/evm/getBaseFee.ts index 7a3460788..05f1d1cf1 100644 --- a/examples/evm/getBaseFee.ts +++ b/examples/evm/getBaseFee.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { EVMAPI } from "../../src/apis/evm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/getMaxPriorityFeePerGas.ts b/examples/evm/getMaxPriorityFeePerGas.ts index ce5eeffcb..ba2928912 100644 --- a/examples/evm/getMaxPriorityFeePerGas.ts +++ b/examples/evm/getMaxPriorityFeePerGas.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { EVMAPI } from "../../src/apis/evm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const cchain: EVMAPI = avalanche.CChain() diff --git a/examples/evm/importTx-avax-to-the-pchain-and-consume-a-multisig-output.ts b/examples/evm/importTx-avax-to-the-pchain-and-consume-a-multisig-output.ts index be5f67045..1ab236ad7 100644 --- a/examples/evm/importTx-avax-to-the-pchain-and-consume-a-multisig-output.ts +++ b/examples/evm/importTx-avax-to-the-pchain-and-consume-a-multisig-output.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { EVMAPI, @@ -18,10 +19,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const cchain: EVMAPI = avalanche.CChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/evm/importTx-xchain.ts b/examples/evm/importTx-xchain.ts index 1154c6ede..38e768187 100644 --- a/examples/evm/importTx-xchain.ts +++ b/examples/evm/importTx-xchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { EVMAPI, @@ -18,10 +19,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const cchain: EVMAPI = avalanche.CChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/health/health.ts b/examples/health/health.ts index 3b60775aa..1cb423133 100644 --- a/examples/health/health.ts +++ b/examples/health/health.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { HealthAPI } from "../../src/apis/health" import { HealthResponse } from "../../src/apis/health/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const health: HealthAPI = avalanche.Health() diff --git a/examples/index/getContainerByID.ts b/examples/index/getContainerByID.ts index 74dc6a876..ea9cef063 100644 --- a/examples/index/getContainerByID.ts +++ b/examples/index/getContainerByID.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { IndexAPI } from "../../src/apis/index" import { GetContainerByIDResponse } from "../../src/apis/index/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const index: IndexAPI = avalanche.Index() diff --git a/examples/index/getContainerByIndex.ts b/examples/index/getContainerByIndex.ts index 3802876de..83c10dc3e 100644 --- a/examples/index/getContainerByIndex.ts +++ b/examples/index/getContainerByIndex.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { IndexAPI } from "../../src/apis/index" import { GetContainerByIndexResponse } from "../../src/apis/index/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const index: IndexAPI = avalanche.Index() diff --git a/examples/index/getContainerRange.ts b/examples/index/getContainerRange.ts index 7262f19c7..0bf092ae6 100644 --- a/examples/index/getContainerRange.ts +++ b/examples/index/getContainerRange.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { IndexAPI } from "../../src/apis/index" import { GetContainerRangeResponse } from "../../src/apis/index/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const index: IndexAPI = avalanche.Index() diff --git a/examples/index/getIndex.ts b/examples/index/getIndex.ts index 71662421d..8aee2e5d1 100644 --- a/examples/index/getIndex.ts +++ b/examples/index/getIndex.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { IndexAPI } from "../../src/apis/index" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const index: IndexAPI = avalanche.Index() diff --git a/examples/index/getLastAccepted.ts b/examples/index/getLastAccepted.ts index caa28eda8..3106d6a13 100644 --- a/examples/index/getLastAccepted.ts +++ b/examples/index/getLastAccepted.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { IndexAPI } from "../../src/apis/index" import { GetLastAcceptedResponse } from "../../src/apis/index/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const index: IndexAPI = avalanche.Index() diff --git a/examples/index/getLastVertex.ts b/examples/index/getLastVertex.ts index 08efcb431..d0ac1aa29 100644 --- a/examples/index/getLastVertex.ts +++ b/examples/index/getLastVertex.ts @@ -1,12 +1,13 @@ +import "dotenv/config" import { Avalanche, BinTools, Buffer } from "../../src" import { IndexAPI } from "../../src/apis/index/index" import { GetLastAcceptedResponse } from "../../src/apis/index/interfaces" import { Vertex } from "../../src/apis/avm" -const ip: string = "indexer-demo.avax.network" -const port: number = 443 -const protocol: string = "https" -const networkID: number = 1 +const ip = process.env.IP_INDEXER +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const index: IndexAPI = avalanche.Index() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/index/isAccepted.ts b/examples/index/isAccepted.ts index b7784c852..04a7f34b6 100644 --- a/examples/index/isAccepted.ts +++ b/examples/index/isAccepted.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { IndexAPI } from "../../src/apis/index" import { IsAcceptedResponse } from "../../src/apis/index/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const index: IndexAPI = avalanche.Index() diff --git a/examples/index/traverseDAG.ts b/examples/index/traverseDAG.ts index 0e75d7d2d..7634266f9 100644 --- a/examples/index/traverseDAG.ts +++ b/examples/index/traverseDAG.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, Buffer } from "../../src" import { Vertex } from "../../src/apis/avm" import { IndexAPI } from "../../src/apis/index" @@ -6,10 +7,10 @@ import { GetLastAcceptedResponse } from "../../src/apis/index/interfaces" -const ip: string = "indexer-demo.avax.network" -const port: number = 443 -const protocol: string = "https" -const networkID: number = 1 +const ip = process.env.IP_INDEXER +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const index: IndexAPI = avalanche.Index() diff --git a/examples/info/getBlockchainID.ts b/examples/info/getBlockchainID.ts index 21ca83004..72a2f0d9b 100644 --- a/examples/info/getBlockchainID.ts +++ b/examples/info/getBlockchainID.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { InfoAPI } from "../../src/apis/info" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const info: InfoAPI = avalanche.Info() diff --git a/examples/info/getNetworkID.ts b/examples/info/getNetworkID.ts index 4b567a8ab..04a95ec4b 100644 --- a/examples/info/getNetworkID.ts +++ b/examples/info/getNetworkID.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { InfoAPI } from "../../src/apis/info" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const info: InfoAPI = avalanche.Info() diff --git a/examples/info/getNetworkName.ts b/examples/info/getNetworkName.ts index 27655dbc0..82448cadd 100644 --- a/examples/info/getNetworkName.ts +++ b/examples/info/getNetworkName.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { InfoAPI } from "../../src/apis/info" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const info: InfoAPI = avalanche.Info() diff --git a/examples/info/getNodeID.ts b/examples/info/getNodeID.ts index 7f42b075c..42108d8a9 100644 --- a/examples/info/getNodeID.ts +++ b/examples/info/getNodeID.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { InfoAPI } from "../../src/apis/info" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const info: InfoAPI = avalanche.Info() diff --git a/examples/info/getNodeVersion.ts b/examples/info/getNodeVersion.ts index 2543c1925..5040ad4c8 100644 --- a/examples/info/getNodeVersion.ts +++ b/examples/info/getNodeVersion.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { InfoAPI } from "../../src/apis/info" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const info: InfoAPI = avalanche.Info() diff --git a/examples/info/getTxFee.ts b/examples/info/getTxFee.ts index 632ab4540..3008a6003 100644 --- a/examples/info/getTxFee.ts +++ b/examples/info/getTxFee.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { InfoAPI } from "../../src/apis/info" import { GetTxFeeResponse } from "../../src/apis/info/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const info: InfoAPI = avalanche.Info() diff --git a/examples/info/isBootstrapped.ts b/examples/info/isBootstrapped.ts index 0e3c2d1a8..25bf7e69d 100644 --- a/examples/info/isBootstrapped.ts +++ b/examples/info/isBootstrapped.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { InfoAPI } from "../../src/apis/info" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const info: InfoAPI = avalanche.Info() diff --git a/examples/info/peers.ts b/examples/info/peers.ts index e01d12bd3..d60e29ec2 100644 --- a/examples/info/peers.ts +++ b/examples/info/peers.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { InfoAPI } from "../../src/apis/info" import { PeersResponse } from "../../src/apis/info/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const info: InfoAPI = avalanche.Info() diff --git a/examples/info/uptime.ts b/examples/info/uptime.ts index 9b37a6ae6..daacf7840 100644 --- a/examples/info/uptime.ts +++ b/examples/info/uptime.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { InfoAPI } from "../../src/apis/info" import { UptimeResponse } from "../../src/apis/info/interfaces" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const info: InfoAPI = avalanche.Info() diff --git a/examples/keystore/createUser.ts b/examples/keystore/createUser.ts index 7ab44664b..a1f11aec4 100644 --- a/examples/keystore/createUser.ts +++ b/examples/keystore/createUser.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { KeystoreAPI } from "../../src/apis/keystore" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const keystore: KeystoreAPI = avalanche.NodeKeys() diff --git a/examples/keystore/deleteUser.ts b/examples/keystore/deleteUser.ts index 2d2376a6c..ffed41613 100644 --- a/examples/keystore/deleteUser.ts +++ b/examples/keystore/deleteUser.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { KeystoreAPI } from "../../src/apis/keystore" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const keystore: KeystoreAPI = avalanche.NodeKeys() diff --git a/examples/keystore/exportUser.ts b/examples/keystore/exportUser.ts index 97ad66230..b931a6286 100644 --- a/examples/keystore/exportUser.ts +++ b/examples/keystore/exportUser.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { KeystoreAPI } from "../../src/apis/keystore" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const keystore: KeystoreAPI = avalanche.NodeKeys() diff --git a/examples/keystore/importUser.ts b/examples/keystore/importUser.ts index a4ddffd25..3a2ab68cd 100644 --- a/examples/keystore/importUser.ts +++ b/examples/keystore/importUser.ts @@ -2,14 +2,15 @@ // which you can create based on "secrets.example" which is in the // root of the `examples/` directory. // Unlike "secrets.example", "secrets.json" should never be committed to git. +import "dotenv/config" import { readFile } from "fs" import { Avalanche } from "../../src" import { KeystoreAPI } from "../../src/apis/keystore" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const keystore: KeystoreAPI = avalanche.NodeKeys() diff --git a/examples/keystore/listUsers.ts b/examples/keystore/listUsers.ts index 82ebe739c..361dcf0b6 100644 --- a/examples/keystore/listUsers.ts +++ b/examples/keystore/listUsers.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { KeystoreAPI } from "../../src/apis/keystore" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const keystore: KeystoreAPI = avalanche.NodeKeys() diff --git a/examples/metrics/getMetrics.ts b/examples/metrics/getMetrics.ts index c536b70a4..8174debc0 100644 --- a/examples/metrics/getMetrics.ts +++ b/examples/metrics/getMetrics.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { MetricsAPI } from "../../src/apis/metrics" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.LOCAL_IP +const port = Number(process.env.LOCAL_PORT) +const protocol = process.env.LOCAL_PROTOCOL +const networkID = Number(process.env.LOCAL_NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const metrics: MetricsAPI = avalanche.Metrics() diff --git a/examples/platformvm/JSONPChainTx.ts b/examples/platformvm/JSONPChainTx.ts index 02a944828..48616d3f0 100644 --- a/examples/platformvm/JSONPChainTx.ts +++ b/examples/platformvm/JSONPChainTx.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, Buffer } from "../../src" import { PlatformVMAPI, Tx } from "../../src/apis/platformvm" -const ip: string = "api.avax.network" -const port: number = 443 -const protocol: string = "https" -const networkID: number = 1 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/addDelegatorTx.ts b/examples/platformvm/addDelegatorTx.ts index b06beb10c..e395a8626 100644 --- a/examples/platformvm/addDelegatorTx.ts +++ b/examples/platformvm/addDelegatorTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -24,10 +25,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/platformvm/addSubnetValidatorTx.ts b/examples/platformvm/addSubnetValidatorTx.ts index c53e43119..86d0b81b1 100644 --- a/examples/platformvm/addSubnetValidatorTx.ts +++ b/examples/platformvm/addSubnetValidatorTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -22,10 +23,10 @@ import { import { Output } from "../../src/common" const bintools: BinTools = BinTools.getInstance() -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() // Keychain with 4 keys-A, B, C, and D @@ -87,7 +88,7 @@ const main = async (): Promise => { const utxos: UTXO[] = utxoSet.getAllUTXOs() utxos.forEach((utxo: UTXO): void => { const output: Output = utxo.getOutput() - if(output.getTypeID() === 7) { + if (output.getTypeID() === 7) { const amountOutput: AmountOutput = utxo.getOutput() as AmountOutput const amt: BN = amountOutput.getAmount().clone() const txid: Buffer = utxo.getTxID() diff --git a/examples/platformvm/addValidatorTx.ts b/examples/platformvm/addValidatorTx.ts index c42e7a6fd..38ae2bf1c 100644 --- a/examples/platformvm/addValidatorTx.ts +++ b/examples/platformvm/addValidatorTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -24,10 +25,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/platformvm/baseTx-avax-create-multisig.ts b/examples/platformvm/baseTx-avax-create-multisig.ts index 49ae251d8..e42fb00eb 100644 --- a/examples/platformvm/baseTx-avax-create-multisig.ts +++ b/examples/platformvm/baseTx-avax-create-multisig.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -21,10 +22,10 @@ import { } from "../../src/utils" const bintools: BinTools = BinTools.getInstance() -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const xBlockchainID: string = Defaults.network[networkID].X.blockchainID const xBlockchainIDBuf: Buffer = bintools.cb58Decode(xBlockchainID) const avaxAssetID: string = Defaults.network[networkID].X.avaxAssetID diff --git a/examples/platformvm/buildAddDelegatorTx.ts b/examples/platformvm/buildAddDelegatorTx.ts index 3d8805c52..54e5b049b 100644 --- a/examples/platformvm/buildAddDelegatorTx.ts +++ b/examples/platformvm/buildAddDelegatorTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -12,10 +13,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const pKeychain: KeyChain = pchain.keyChain() diff --git a/examples/platformvm/buildAddSubnetValidatorTx.ts b/examples/platformvm/buildAddSubnetValidatorTx.ts index fece8b653..eb42a02f9 100644 --- a/examples/platformvm/buildAddSubnetValidatorTx.ts +++ b/examples/platformvm/buildAddSubnetValidatorTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -13,10 +14,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() // Keychain with 4 keys-A, B, C, and D diff --git a/examples/platformvm/buildAddValidatorTx.ts b/examples/platformvm/buildAddValidatorTx.ts index 646ec8bfc..f72ca4d73 100644 --- a/examples/platformvm/buildAddValidatorTx.ts +++ b/examples/platformvm/buildAddValidatorTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -12,10 +13,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const pKeychain: KeyChain = pchain.keyChain() diff --git a/examples/platformvm/buildCreateChainTx.ts b/examples/platformvm/buildCreateChainTx.ts index e0f15e31d..a88dec17f 100644 --- a/examples/platformvm/buildCreateChainTx.ts +++ b/examples/platformvm/buildCreateChainTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer, GenesisData } from "../../src" import { PlatformVMAPI, @@ -16,10 +17,10 @@ import { * @ignore */ const bintools: BinTools = BinTools.getInstance() -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() // Keychain with 4 keys-A, B, C, and D diff --git a/examples/platformvm/buildCreateSubnetTx.ts b/examples/platformvm/buildCreateSubnetTx.ts index 96b2bcdab..c3ebe7e9a 100644 --- a/examples/platformvm/buildCreateSubnetTx.ts +++ b/examples/platformvm/buildCreateSubnetTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -13,10 +14,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() // Keychain with 4 keys-A, B, C, and D diff --git a/examples/platformvm/buildExportTx-CChain.ts b/examples/platformvm/buildExportTx-CChain.ts index 4e737f65e..450f73f19 100644 --- a/examples/platformvm/buildExportTx-CChain.ts +++ b/examples/platformvm/buildExportTx-CChain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, KeyChain as AVMKeyChain } from "../../src/apis/avm" import { @@ -14,10 +15,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/buildExportTx-XChain.ts b/examples/platformvm/buildExportTx-XChain.ts index 82ed1f1f8..af715b835 100644 --- a/examples/platformvm/buildExportTx-XChain.ts +++ b/examples/platformvm/buildExportTx-XChain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { AVMAPI, KeyChain as AVMKeyChain } from "../../src/apis/avm" import { @@ -14,10 +15,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/buildImportTx-CChain.ts b/examples/platformvm/buildImportTx-CChain.ts index 651734792..e6e21352c 100644 --- a/examples/platformvm/buildImportTx-CChain.ts +++ b/examples/platformvm/buildImportTx-CChain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -13,10 +14,10 @@ import { UnixNow } from "../../src//utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const pKeychain: KeyChain = pchain.keyChain() diff --git a/examples/platformvm/buildImportTx-XChain.ts b/examples/platformvm/buildImportTx-XChain.ts index 35c57d3e5..c80244e08 100644 --- a/examples/platformvm/buildImportTx-XChain.ts +++ b/examples/platformvm/buildImportTx-XChain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -13,10 +14,10 @@ import { UnixNow } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const pKeychain: KeyChain = pchain.keyChain() diff --git a/examples/platformvm/createChainTx.ts b/examples/platformvm/createChainTx.ts index 784367b14..b62917f36 100644 --- a/examples/platformvm/createChainTx.ts +++ b/examples/platformvm/createChainTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, @@ -29,10 +30,10 @@ import { } from "../../src/utils" const bintools: BinTools = BinTools.getInstance() -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() // Keychain with 4 keys-A, B, C, and D diff --git a/examples/platformvm/createKeypair.ts b/examples/platformvm/createKeypair.ts index ad37d1ac0..bb4631552 100644 --- a/examples/platformvm/createKeypair.ts +++ b/examples/platformvm/createKeypair.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { PlatformVMAPI, KeyChain, KeyPair } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/createSubnetTx.ts b/examples/platformvm/createSubnetTx.ts index 04c15a01f..276987e24 100644 --- a/examples/platformvm/createSubnetTx.ts +++ b/examples/platformvm/createSubnetTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -21,10 +22,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const bintools: BinTools = BinTools.getInstance() @@ -90,7 +91,7 @@ const main = async (): Promise => { const utxos: UTXO[] = utxoSet.getAllUTXOs() utxos.forEach((utxo: UTXO): void => { const output: Output = utxo.getOutput() - if(output.getTypeID() === 7) { + if (output.getTypeID() === 7) { const amountOutput = utxo.getOutput() as AmountOutput const amt: BN = amountOutput.getAmount().clone() const txid: Buffer = utxo.getTxID() diff --git a/examples/platformvm/exportTx-AVAX-from-the-cchain-and-create-a-multisig-atomic-output.ts b/examples/platformvm/exportTx-AVAX-from-the-cchain-and-create-a-multisig-atomic-output.ts index 950cc39e5..d3959ebf8 100644 --- a/examples/platformvm/exportTx-AVAX-from-the-cchain-and-create-a-multisig-atomic-output.ts +++ b/examples/platformvm/exportTx-AVAX-from-the-cchain-and-create-a-multisig-atomic-output.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { EVMAPI, KeyChain as EVMKeyChain } from "../../src/apis/evm" import { @@ -21,10 +22,10 @@ import { MILLIAVAX } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const cchain: EVMAPI = avalanche.CChain() const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/exportTx-cchain.ts b/examples/platformvm/exportTx-cchain.ts index e38d269fe..383ba8b05 100644 --- a/examples/platformvm/exportTx-cchain.ts +++ b/examples/platformvm/exportTx-cchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { EVMAPI, KeyChain as EVMKeyChain } from "../../src/apis/evm" import { @@ -21,10 +22,10 @@ import { MILLIAVAX } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const cchain: EVMAPI = avalanche.CChain() const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/exportTx-xchain.ts b/examples/platformvm/exportTx-xchain.ts index 93d51a256..65356eb6c 100644 --- a/examples/platformvm/exportTx-xchain.ts +++ b/examples/platformvm/exportTx-xchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { AVMAPI, KeyChain as AVMKeyChain } from "../../src/apis/avm" import { @@ -22,10 +23,10 @@ import { MILLIAVAX } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const xchain: AVMAPI = avalanche.XChain() const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getBalance.ts b/examples/platformvm/getBalance.ts index 3294c52f9..f5381e162 100644 --- a/examples/platformvm/getBalance.ts +++ b/examples/platformvm/getBalance.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "api.avax.network" -const port: number = 443 -const protocol: string = "https" -const networkID: number = 5 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getBlockchainStatus.ts b/examples/platformvm/getBlockchainStatus.ts index 9f22bf68f..df8dd1b47 100644 --- a/examples/platformvm/getBlockchainStatus.ts +++ b/examples/platformvm/getBlockchainStatus.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getBlockchains.ts b/examples/platformvm/getBlockchains.ts index aa5de0455..5bac8a198 100644 --- a/examples/platformvm/getBlockchains.ts +++ b/examples/platformvm/getBlockchains.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getCurrentSupply.ts b/examples/platformvm/getCurrentSupply.ts index 633a1eabe..420f6ec1d 100644 --- a/examples/platformvm/getCurrentSupply.ts +++ b/examples/platformvm/getCurrentSupply.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche, BN } from "../../src" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getCurrentValidators.ts b/examples/platformvm/getCurrentValidators.ts index 0b2946e36..06eecf413 100644 --- a/examples/platformvm/getCurrentValidators.ts +++ b/examples/platformvm/getCurrentValidators.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getPendingValidators.ts b/examples/platformvm/getPendingValidators.ts index 8905d7680..1a4e28a44 100644 --- a/examples/platformvm/getPendingValidators.ts +++ b/examples/platformvm/getPendingValidators.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getRewardUTXOs.ts b/examples/platformvm/getRewardUTXOs.ts index 2845bd0e1..242ede14d 100644 --- a/examples/platformvm/getRewardUTXOs.ts +++ b/examples/platformvm/getRewardUTXOs.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { GetRewardUTXOsResponse } from "../../src/apis/platformvm/interfaces" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getStake.ts b/examples/platformvm/getStake.ts index 3d3ca0d19..568cb7aa6 100644 --- a/examples/platformvm/getStake.ts +++ b/examples/platformvm/getStake.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { PlatformVMAPI, KeyChain } from "../../src/apis/platformvm" import { GetStakeResponse } from "../../src/apis/platformvm/interfaces" @@ -6,10 +7,10 @@ import { DefaultLocalGenesisPrivateKey } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const pKeychain: KeyChain = pchain.keyChain() diff --git a/examples/platformvm/getStakingAssetID.ts b/examples/platformvm/getStakingAssetID.ts index c6195ea9e..526c8b8e6 100644 --- a/examples/platformvm/getStakingAssetID.ts +++ b/examples/platformvm/getStakingAssetID.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getSubnets.ts b/examples/platformvm/getSubnets.ts index 53c729db6..7b585805c 100644 --- a/examples/platformvm/getSubnets.ts +++ b/examples/platformvm/getSubnets.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getTx.ts b/examples/platformvm/getTx.ts index 2f8f9aa9e..f99a33e52 100644 --- a/examples/platformvm/getTx.ts +++ b/examples/platformvm/getTx.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getTxStatus.ts b/examples/platformvm/getTxStatus.ts index 0642b3afb..7293a26e8 100644 --- a/examples/platformvm/getTxStatus.ts +++ b/examples/platformvm/getTxStatus.ts @@ -1,10 +1,11 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/getValidatorsAt.ts b/examples/platformvm/getValidatorsAt.ts index e709e3b3c..a66910b04 100644 --- a/examples/platformvm/getValidatorsAt.ts +++ b/examples/platformvm/getValidatorsAt.ts @@ -1,11 +1,12 @@ +import "dotenv/config" import { Avalanche } from "../../src" import { GetValidatorsAtResponse } from "../../src/apis/platformvm/interfaces" import { PlatformVMAPI } from "../../src/apis/platformvm" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() diff --git a/examples/platformvm/importTx-avax-cchain-create-multisig.ts b/examples/platformvm/importTx-avax-cchain-create-multisig.ts index 5a29eb6fe..adcc37011 100644 --- a/examples/platformvm/importTx-avax-cchain-create-multisig.ts +++ b/examples/platformvm/importTx-avax-cchain-create-multisig.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -19,10 +20,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/platformvm/importTx-avax-from-the-xchain-and-create-a-multisig-utxo.ts b/examples/platformvm/importTx-avax-from-the-xchain-and-create-a-multisig-utxo.ts index 59b7f2af6..c9b44488c 100644 --- a/examples/platformvm/importTx-avax-from-the-xchain-and-create-a-multisig-utxo.ts +++ b/examples/platformvm/importTx-avax-from-the-xchain-and-create-a-multisig-utxo.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -19,10 +20,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/platformvm/importTx-avax-to-the-P-Chain-from-the-C-Chain-and-consume-a-multisig-atomic-output-and-a-create-multisig-output.ts b/examples/platformvm/importTx-avax-to-the-P-Chain-from-the-C-Chain-and-consume-a-multisig-atomic-output-and-a-create-multisig-output.ts index 5a29eb6fe..adcc37011 100644 --- a/examples/platformvm/importTx-avax-to-the-P-Chain-from-the-C-Chain-and-consume-a-multisig-atomic-output-and-a-create-multisig-output.ts +++ b/examples/platformvm/importTx-avax-to-the-P-Chain-from-the-C-Chain-and-consume-a-multisig-atomic-output-and-a-create-multisig-output.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -19,10 +20,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/platformvm/importTx-xchain.ts b/examples/platformvm/importTx-xchain.ts index 62110cfff..23413caec 100644 --- a/examples/platformvm/importTx-xchain.ts +++ b/examples/platformvm/importTx-xchain.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -19,10 +20,10 @@ import { Defaults } from "../../src/utils" -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const bintools: BinTools = BinTools.getInstance() diff --git a/examples/platformvm/proofOfPossession.ts b/examples/platformvm/proofOfPossession.ts index 7c4c852c3..3c84d0182 100644 --- a/examples/platformvm/proofOfPossession.ts +++ b/examples/platformvm/proofOfPossession.ts @@ -1,5 +1,6 @@ // using https://www.npmjs.com/package/@noble/bls12-381 // import { getPublicKey, sign, verify } from "@noble/bls12-381" +import "dotenv/config" import { Avalanche, Buffer } from "../../src" import { KeyChain, @@ -9,15 +10,21 @@ import { } from "../../src/apis/platformvm" // start placeholder functions -const getPublicKey = (privateKey): Buffer => {return new Buffer("00")} -const sign = (publicKey, privateKey): Buffer => {return new Buffer("00")} -const verify = (signature, message, publicKey): boolean => {return true} +const getPublicKey = (privateKey): Buffer => { + return new Buffer("00") +} +const sign = (publicKey, privateKey): Buffer => { + return new Buffer("00") +} +const verify = (signature, message, publicKey): boolean => { + return true +} // end placeholder functions -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() const keychain: KeyChain = pchain.keyChain() @@ -28,7 +35,7 @@ const main = async (): Promise => { // 48 byte public key const publicKey = getPublicKey(privateKey) as Buffer // 96 byte signature - const signature = await sign(publicKey, privateKey) as Buffer + const signature = (await sign(publicKey, privateKey)) as Buffer const proofOfPossession: ProofOfPossession = new ProofOfPossession( publicKey, signature diff --git a/examples/platformvm/removeSubnetValidatorTx.ts b/examples/platformvm/removeSubnetValidatorTx.ts index 539dcb7ba..caa166c20 100644 --- a/examples/platformvm/removeSubnetValidatorTx.ts +++ b/examples/platformvm/removeSubnetValidatorTx.ts @@ -1,3 +1,4 @@ +import "dotenv/config" import { Avalanche, BinTools, BN, Buffer } from "../../src" import { PlatformVMAPI, @@ -22,10 +23,10 @@ import { } from "../../src/utils" const bintools: BinTools = BinTools.getInstance() -const ip: string = "localhost" -const port: number = 9650 -const protocol: string = "http" -const networkID: number = 1337 +const ip = process.env.IP +const port = Number(process.env.PORT) +const protocol = process.env.PROTOCOL +const networkID = Number(process.env.NETWORK_ID) const avalanche: Avalanche = new Avalanche(ip, port, protocol, networkID) const pchain: PlatformVMAPI = avalanche.PChain() // Keychain with 4 keys-A, B, C, and D @@ -85,7 +86,7 @@ const main = async (): Promise => { const utxos: UTXO[] = utxoSet.getAllUTXOs() utxos.forEach((utxo: UTXO): void => { const output: Output = utxo.getOutput() - if(output.getTypeID() === 7) { + if (output.getTypeID() === 7) { const amountOutput: AmountOutput = utxo.getOutput() as AmountOutput const amt: BN = amountOutput.getAmount().clone() const txid: Buffer = utxo.getTxID() @@ -108,15 +109,16 @@ const main = async (): Promise => { "8T4oUrP7kXzetGF2bYWF21oJHUT18rJCjfBt3J299hA1Smcqa" ) const nodeIDBuf: Buffer = NodeIDStringToBuffer(nodeID) - const removeSubnetValidatorTx: RemoveSubnetValidatorTx = new RemoveSubnetValidatorTx( - networkID, - pChainBlockchainIDBuf, - outputs, - inputs, - memo, - nodeIDBuf, - subnetID - ) + const removeSubnetValidatorTx: RemoveSubnetValidatorTx = + new RemoveSubnetValidatorTx( + networkID, + pChainBlockchainIDBuf, + outputs, + inputs, + memo, + nodeIDBuf, + subnetID + ) removeSubnetValidatorTx.addSignatureIdx(0, pAddresses[3]) removeSubnetValidatorTx.addSignatureIdx(1, pAddresses[1]) const unsignedTx: UnsignedTx = new UnsignedTx(removeSubnetValidatorTx) diff --git a/examples/socket/newBloom.ts b/examples/socket/newBloom.ts index 31a855895..3466a056c 100644 --- a/examples/socket/newBloom.ts +++ b/examples/socket/newBloom.ts @@ -1,8 +1,9 @@ +import "dotenv/config" import { PubSub, Socket } from "../../src" -const protocol: string = "ws" -const host: string = "localhost" -const port: number = 9650 +const protocol = process.env.PROTOCOL_WS +const host = process.env.LOCALHOST +const port = Number(process.env.PORT) const addresses: string[] = ["X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u"] const main = async (): Promise => { diff --git a/examples/socket/newSet.ts b/examples/socket/newSet.ts index 10c923193..31d8f5eef 100644 --- a/examples/socket/newSet.ts +++ b/examples/socket/newSet.ts @@ -1,8 +1,9 @@ +import "dotenv/config" import { PubSub, Socket } from "../../src" -const protocol: string = "ws" -const host: string = "localhost" -const port: number = 9650 +const protocol = process.env.PROTOCOL_WS +const host = process.env.LOCALHOST +const port = Number(process.env.PORT) const addresses: string[] = ["X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u"] const main = async (): Promise => { diff --git a/package.json b/package.json index f941f1198..528487819 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "buffer": "6.0.3", "create-hash": "1.2.0", "crypto-browserify": "3.12.0", + "dotenv": "^16.3.1", "elliptic": "6.5.4", "ethers": "6.0.8", "hdkey": "2.1.0", diff --git a/src/avalanche.ts b/src/avalanche.ts index d83d7761a..5ed15a234 100644 --- a/src/avalanche.ts +++ b/src/avalanche.ts @@ -50,7 +50,7 @@ export default class AvalancheCore { * &#,@+()$~%'":*?{} also less than and greater than signs */ setAddress = ( - host: string, + host: string | undefined, port: number, protocol: string = "http", baseEndpoint: string = "" diff --git a/yarn.lock b/yarn.lock index b6f286bc5..93a6c6aaf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2978,6 +2978,11 @@ dot-prop@^5.1.0: dependencies: is-obj "^2.0.0" +dotenv@^16.3.1: + version "16.3.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" + integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== + duplexer2@~0.1.0: version "0.1.4" resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1"