Ich habe zwei Verträge, contractA
& contractB
. Ich möchte, dass Truffle zuerst bereitstellt contractA
und es dann als Argument an contractB
den Konstruktor von übergibt.
Dies ist, was ich gerade versuche, aber contractB
nie wirklich eingesetzt wird:
let contractA = artifacts.require("./contractA.sol");
let contractB = artifacts.require("./contractB.sol");
module.exports = async function(deployer, network) {
await deployer.deploy(contractA); // this gets deployed fine
deployer.deploy(contractB, contractA.address); // this *never* gets deployed
};
Tatsächlich wird contractB
es nicht bereitgestellt, selbst wenn ich den Code wie folgt ändere:
await deployer.deploy(contractA);
deployer.deploy(contractB, "0x123"); // does not deploy even if I enter the address manually
Was fehlt mir hier?
Versuche dies:
deployer.then(async function() {
let contractA = await artifacts.require("A").new();
let contractB = await artifacts.require("B").new(contractA._address);
});
Ich konnte dies endlich lösen, indem ich mehrere Truffle-Bereitstellungsdateien erstellte.
2_deploy_contractA.js:
// 2_deploy_contractA.js
let contractA = artifacts.require("./contractA.sol");
module.exports = function(deployer, network) {
deployer.deploy(contractA);
};
3_deploy_contractB.js:
// 3_deploy_contractB.js
let contractA = artifacts.require("./contractA.sol");
let contractB = artifacts.require("./contractB.sol");
module.exports = function(deployer, network) {
deployer.deploy(contractB, contractA.address);
};
Tarek
contractA
gibtundefined
.gute Stimmung
"A.sol"
? Ich habe dies als Beispiel geschrieben, ich kann Ihre Dateinamen nicht erraten, also habe ich dieselben Abkürzungen wie in Ihrer Frage verwendet.Tarek
A.sol
gute Stimmung
"A.sol"
. So mache ich es normalerweise (ich dachte nur, es wäre ohne erlaubt, wie in den offiziellen Truffle-Dokumenten empfohlen).Tarek
gute Stimmung
truffle compile
, erhalten Sie eine Datei mit dem NamenA.json
im Artefaktordner?Tarek