Lassen Sie Truffle einen Vertrag bereitstellen und übergeben Sie ihn als Argument an den Konstruktor eines anderen Vertrags

Ich habe zwei Verträge, contractA& contractB. Ich möchte, dass Truffle zuerst bereitstellt contractAund es dann als Argument an contractBden Konstruktor von übergibt.

Dies ist, was ich gerade versuche, aber contractBnie 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 contractBes 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?

Antworten (2)

Versuche dies:

deployer.then(async function() {
    let contractA = await artifacts.require("A").new();
    let contractB = await artifacts.require("B").new(contractA._address);
});
Scheint bei mir nicht zu funktionieren. Die Konsolenprotokollierung contractAgibt undefined.
Nun, ist Ihr Vertrag wirklich in einer Datei namens gespeichert "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.
Ja es istA.sol
Nun, vielleicht ändern Sie es in "A.sol". So mache ich es normalerweise (ich dachte nur, es wäre ohne erlaubt, wie in den offiziellen Truffle-Dokumenten empfohlen).
Ja das auch schon probiert.
Wenn Sie ausführen truffle compile, erhalten Sie eine Datei mit dem Namen A.jsonim Artefaktordner?
Ja, die JSON-Datei wird generiert. Ich habe gerade meine Frage mit meinem aktuellen Status aktualisiert.

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);
};