Configuring
Introduction
As we previously saw, in order to get a hold on a precious session, one would need to call one of the 2 available static-factory methods:
ApiSession.default(params?, path?)
ApiSession.buildFrom(StratoContext)
Both of them return a Promise which, when resolved, give back the ApiSession
instance to play with. In fact, ApiSession.buildFrom(StratoContext)
is wrapped by it's default
sibling which, we could argue, will most likely probability end up to being used the most.
This section describes the arguments of ApiSession.default
and how they can be used to obtain a session to operate on.
The default
session can be procured in one of the 4 following ways:
ApiSession.default()
- run most often with no arguments at all, in which case it will try to load the parameters from the environment file present atHEDERAS_ENV_PATH
environment-variable path or, if not specified, default loading the.env
from repo-root. This is basically equivalent to callingApiSession.default({}, path = process.env.HEDERAS_ENV_PATH || '.env')
ApiSession.default(path)
- parse params present atpath
env-file location. This ends up runningApiSession.default({}, path)
ApiSession.default(params)
- build the desired context unpacking a runtime representation of a json object. This is equivalent to runningApiSession.default(params, path = process.env.HEDERAS_ENV_PATH || '.env')
ApiSession.default(params, path)
- creates a session-execution context (StratoContext
) by doing a parameter resolution over the provided arguments
Following is a table detailing all the object-parameters along with their environmental variables counterparts which can be used to bootstrap a Venin session.
Big table o' parameters
Environment Variable | Parameter Property | Required | Type | Default | Description |
---|---|---|---|---|---|
HEDERAS_WALLET_CONTROLLER_DEFAULT_PRIVATE_KEY | wallet.controller.default.operatorKey | 6 | - | - | The private-key used by the operators when switching accounts on a Sdk wallet using a DefaultPrivateKeyWalletController |
HEDERAS_WALLET_CONTROLLER | wallet.controller.type | - | Hedera , DefaultPrivateKey | Hedera | The type of wallet-controller deployed. It's basically laying out the foundation of wallet-integration since a controller can propagate either an account-change or a network change. |
HEDERAS_WALLET_TYPE | wallet.type | No | Sdk | Sdk | The wallet type used for the underlying session interactions (see wallets guide) |
HEDERAS_WALLET_WINDOW_PROPERTY_NAME | wallet.window.propName | No | string | hedera | When bundling, the property location of the HIP-338 compliant wallet definition available on the global, window object |
HEDERAS_CONTRACTS_INCLUDED_PREFIXES | - | No | 5 | contracts | The places to search for imported contract paths from within a solidity code. The contract's parent folder is the first one being searched, followed by the project's node_modules and then, if nothing matches, the rest of the included prefixes are looked at in the order in which they are defined |
HEDERAS_CONTRACTS_RELATIVE_PATH | - | No | path | contracts | The name of the folder relative to the project root directory where all the solidity contracts are expected to reside. This is used when Venin is doing the contract compiling of a given relative-pathed contract |
HEDERAS_DEFAULT_CONTRACT_CREATION_GAS | session.defaults.contractCreationGas | No | number | 150000 | The default amount spent for creating a contract on the network |
HEDERAS_DEFAULT_CONTRACT_REQUESTS_RETURN_ONLY_RECEIPTS | session.defaults.onlyReceiptsFromContractRequests | No | boolean | true | true to return only receipts for all state-mutating/transactions live-contract call, false otherwise. Contract queries (non-mutating calls) are not affected by this param. If desired, can be tweaked by the onlyReceipt contract-call meta-argument at an individual level. |
HEDERAS_DEFAULT_CONTRACT_TRANSACTION_GAS | session.defaults.contractTransactionGas | No | number | 169000 | The default amount given when executing a contract transaction |
HEDERAS_DEFAULT_EMIT_CONSTRUCTOR_LOGS | session.defaults.emitConstructorLogs | No | boolean | true | true to emit the constructor logs at contract-creation time, false otherwise |
HEDERAS_DEFAULT_EMIT_LIVE_CONTRACT_RECEIPTS | session.defaults.emitLiveContractReceipts | No | boolean | false | true to ask for and emit the receipts originating from live-contract calls, false otherwise |
HEDERAS_DEFAULT_PAYMENT_FOR_CONTRACT_QUERY | session.defaults.paymentForContractQuery | No | number | 20000000 | The default amount of tinybars payed for doing a contract query call. |
HEDERAS_NETWORK | network.name | Yes | previewnet , testnet , mainnet , customnet | - | The network profile to use |
HEDERAS_NODES | network.nodes | 4 | 3 | - | A condensed address-book representation of the network nodes (see3) |
HEDERAS_OPERATOR_ID | wallet.hedera.operatorId | 2 | - | - | The account-id of the operator running a Sdk wallet |
HEDERAS_OPERATOR_KEY | wallet.hedera.operatorKey | 2 | - | - | The operator private-key of the operator running a Sdk wallet |
HEDERAS_LOGGER_LEVEL | logger.level | No | error , warn , info , verbose , debug , silly | info | The logger sensitivity 1 |
HEDERAS_LOGGER_ENABLED | logger.enabled | No | boolean | false | true to enable the logger, false otherwise |
HEDERAS_ENV_PATH | - | No | path | .env | The path of the .env like file used to source the config parameters from |
Parameters resolution
The default context parameters are being resolved in the following order:
- First, the runtime object-argument is checked and if a config property is present there, that's the one being used otherwise
- If
process.env
(nodejs-case) contains that equivalent environment variable, that is the one which will be used else - If the
HEDERAS_ENV_PATH
environment file path has been supplied, exists and contains the same keys expected inprocess.env
, it will be used else - If a
.env
file exists and it contains the same key expected inprocess.env
, that's one is being used.
If none of the above conditions are true and the parameter is not mandatory, the default value is loaded or an error eventually propagates.
- see https://github.com/winstonjs/winston#logging↩
- required if
HEDERAS_WALLET_TYPE
/wallet.type
isSdk
(the default)↩ - a comma separated string of node-network addresses having the following format :
<ip>:<port>#<account_id>
eg127.0.0.2:52111#3
to make an address-book of one node located at127.0.0.1
, port52111
having account-id0.0.3
↩ - required if
HEDERAS_NETWORK
/network.name
iscustomnet
↩ - a comma separated list of relative folder paths to look at when importing a relative solidity contract-file from within one of the contracts that we wish to compile↩
- required if
HEDERAS_WALLET_CONTROLLER_TYPE
isDefaultPrivateKey
↩