Skip to content

Commit 6933acc

Browse files
authored
Merge pull request #5 from semiotic-ai/fix/write-envs
fix: add script to substitute envs in /src code
2 parents ad71e60 + f6b7be2 commit 6933acc

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ It will stop indexing the old code, and start the new one in its place.
5252

5353
### filling .env
5454

55-
There are contract addresses in `.env.exmaple` that must be chosen
56-
based on the network. Put them into a `.env` for proper usage
55+
The subgraph can't load a `.env` by itself because all handlers are compiled and stored in IPFS.
56+
In this scenario, the environment variables have to be already loaded in the code itself. A script in the
57+
root called `replace-env.js` is provided and used in the scripts to handle this problem.
58+
5759

60+
There are contract addresses in `.env.exmaple` that must be chosen
61+
based on the network. Put them into a `.env` for proper usage.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
},
77
"scripts": {
88
"codegen": "graph codegen",
9-
"build": "graph build",
9+
"build": "node replace-env.js && graph build",
1010
"prepare:sepolia": "mustache config/sepolia.json subgraph.template.yaml > subgraph.yaml",
1111
"prepare:arb-sepolia": "mustache config/arb-sepolia.json subgraph.template.yaml > subgraph.yaml",
12-
"deploy": "graph deploy --node https://api.studio.thegraph.com/deploy/ tap-v2",
12+
"deploy": "node replace-env && graph deploy --node https://api.studio.thegraph.com/deploy/ tap-v2",
1313
"create-local": "graph create --node http://localhost:8020/ tap-v2",
1414
"remove-local": "graph remove --node http://localhost:8020/ tap-v2",
1515
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 tap-v2",

replace-env.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
require('dotenv').config();
4+
5+
const filePath = path.resolve(__dirname, './src/tap-utils.ts');
6+
let fileContent = fs.readFileSync(filePath, 'utf8');
7+
8+
fileContent = fileContent.replace(/{COLLECTOR_ADDRESS}/g, process.env.COLLECTOR_ADDRESS);
9+
10+
fs.writeFileSync(filePath, fileContent);
11+
console.log('Environment variables replaced in mapping files.');

src/tap-utils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import {
1111
const ZERO_BI = BigInt.fromI32(0)
1212
const ZERO_AD = Address.zero()
1313

14-
15-
export const TAP_COLLECTOR = Address.fromString(String(process.env.COLLECTOR_ADDRESS));
14+
export const TAP_COLLECTOR = Address.fromString("{COLLECTOR_ADDRESS}");
1615

1716
export function createOrLoadPayer(id: Bytes): Payer {
1817
let payer = Payer.load(id)
@@ -99,4 +98,4 @@ export function createOrLoadDataService(id: Bytes): DataService {
9998
dataService.save()
10099
}
101100
return dataService as DataService
102-
}
101+
}

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,11 @@ [email protected]:
13581358
docker-modem "^1.0.8"
13591359
tar-fs "~1.16.3"
13601360

1361+
dotenv@^16.4.5:
1362+
version "16.4.7"
1363+
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.7.tgz#0e20c5b82950140aa99be360a8a5f52335f53c26"
1364+
integrity sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==
1365+
13611366
13621367
version "3.1.8"
13631368
resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.8.tgz#758d32910c78047585c7ef1f92f9ee041c1c190b"

0 commit comments

Comments
 (0)