uuosio / ascdk

MIT License
12 stars 9 forks source link

Able to to include environment/config variables #63

Closed DenisCarriere closed 2 years ago

DenisCarriere commented 2 years ago

Ability to include custom environment variables at compile time.

Use default .env file or config/default.json

Override env/config with specific file path

npx eosio-asc contract.ts --env .env
npx eosio-asc contract.ts --config ./config/default.json

Code example

import { print, Name } from "as-chain"

const config = process.env.get("CONFIG");

@contract
class MyContract {
    constructor(
        public receiver: Name,
        public firstReceiver: Name,
        public action: Name) {
    }

    @action("sayhello")
    sayHello():  void {
        print(`hello! ${config}`);
    }
}
DenisCarriere commented 2 years ago

using process.env.get() would receive the following error when deploying contract:

image
learnforpractice commented 2 years ago

I recommend using the method in the following example in order to avoid increasing code size and reducing performance.

https://github.com/uuosio/ascdk/tree/master/examples/config

DenisCarriere commented 2 years ago

Thanks for the suggestion, that should do the trick for configuration