Closed fvictorio closed 6 years ago
@fvictorio there's a /
missing in step 3, right?
Should it be: ./node_modules/.bin/truffle migrate --network test
?
@matiasgaratortiz @fvictorio what do you think about this: we add the following to the bottom of blockchain/migrations/1522104575_popa.js
:
...
if (process.env.SAVE_OUTPUT) {
let fs = require('fs');
let path = require('path');
let contractOutputPath = path.join(__dirname, '../../web-dapp/src/contract-output.json');
let contractData = await POPA.deployed();
let contractOutputJson = {};
contractOutputJson.ProofOfPhysicalAddress = {
address: contractData.address,
abi: contractData.abi
};
console.log('Saving contract output to: ' + contractOutputPath);
fs.writeFileSync(contractOutputPath, JSON.stringify(contractOutputJson, null, 4), 'utf8');
}
then we can run migration as
SAVE_OUTPUT=1 ./node_modules/.bin/truffle migrate --network test
it will create/rewrite contract-output.json
.
@phahulin My concern with an approach like that is, how does that affect the app deploy? I guess the server won't be responsible for deploying the contracts, and it seems like contract-output
is not added to git.
Besides, and at least in my experience, env variables are more flexible (for example, if for some reason the contract needs to be re-deployed, it can be done just modifying an env var in whatever service is used for serving the app, e.g. Heroku).
Yes, deployment to the "real" network can be done manually. Initially I didn't add contract-output.json
to git because keeping a file for a particular network in the repo would make the whole repo too specific.
You're probably right that we should support env
vars, but we also have other variables that would need to be updated this way, those set in web-dapp/server-config-private.js
. It's like env but not in plain text :)
Yes, I agree. Specially things like LOB's API key. Maybe we should create an issue for doing that?
Great, thanks!
Totals | |
---|---|
Change from base Build 261: | -0.07% |
Covered Lines: | 799 |
Relevant Lines: | 1046 |
After the changes that @Janther made, the PoPA contract is not a standalone contract anymore, so the best way to compile it and deploy it is via
truffle
. But this means that we can't usecontract-output.json
anymore to get the address and the ABI of the PoPA contract.This PR gets the address and the ABI from the environment. So now, for starting the app, you have to follow these steps:
.env
in the root of the project. Just copying the example (cp .env.example .env
) should be enough.npm run start-testrpc
blockchain
directory and run./node_modules/.bin/truffle migrate --network test
npm start
For this to work, I had to do several hacky things:
REACT_APP
because otherwise the build of the frontend can't access them.web-dapp/.env
to../.env
because otherwise the react build won't find it. We need both files, because apparentlydotenv
searches the.env
file relative to where the process is running, and we runnpm start
from the root.blockchain/build/contracts/ProofOfPhysicalAddress.json
, butcreate-react-app
doesn't allowrequire
ing from outside its directory, so we would need more symlink magic, or to move theblockchain
directory next to the frontend assets. I think just having the ABI in the environment is easier.Keep in mind that this means that if we change the PoPA contract we'll need to udate the env variable.
Please test this and let me know if you have any issues.