ОБНОВЛЕНО НИЖЕ: (Что сработало для меня)
При компиляции и запуске следующего кода в Remix. Когда я пытаюсь инициализировать Master с помощью _ownerName, я получаю следующую ошибку: «Этот контракт не реализует все функции и, следовательно, не может быть создан».
Я хотел создать новые контракты с клиентами, используя контракт CustomerTemplate.
pragma solidity ^0.4.11;
//------------------------------------------------------------------------------------
//----- Templates
//-----
//------------------------------------------------------------------------------------
contract CustomerTemplate {
bytes32 public customerName;
bytes32 public customerLoc;
function CustomerTemplate (bytes32 _customerName, bytes32 _customerLoc) {
customerName = _customerName;
customerLoc = _customerLoc;
}
}
//------------------------------------------------------------------------------------
//----- Master
//----- Initialize Customer Master with Customer Name and Total Budget
//------------------------------------------------------------------------------------
contract Master is CustomerTemplate{
address public owner;
bytes32 public ownerName;
address[] newCustomers;
modifier onlyByMaster() {
require(msg.sender == owner);
_;
}
function Master (bytes32 _ownerName) {
owner = msg.sender;
ownerName = _ownerName;
}
function createCustomer (bytes32 _customerName, bytes32 _customerLoc) {
address myCustomer = new CustomerTemplate(_customerName, _customerLoc);
newCustomers.push(myCustomer);
}
function killContract() constant onlyByMaster {
if (msg.sender == owner) selfdestruct(owner);
}
}
(ОБНОВЛЕНИЕ) У меня сработало следующее:
pragma solidity ^0.4.15;
contract Template {
bytes32 public custName;
bytes32 public custLoc;
address public contractAddress;
function Template () {
custName = "0xDEFAULT";
custLoc = "0xDEFAULT";
contractAddress = address(this);
}
function AssignCustomerAttributes (bytes32 _custName, bytes32 _custLoc)
returns (bool isSuccess) {
custName = _custName;
custLoc = _custLoc;
contractAddress = address(this);
return true;
}
}
//------------------------------------------------------------------------------------
//----- Master
//----- Initialize Customer Master with Customer Name and Total Budget
//------------------------------------------------------------------------------------
pragma solidity ^0.4.15;
contract Template {
bytes32 public custName;
bytes32 public custLoc;
address public contractAddress;
function Template () {
custName = "0xDEFAULT";
custLoc = "0xDEFAULT";
contractAddress = address(this);
}
function AssignCustomerAttributes (bytes32 _custName, bytes32 _custLoc)
returns (bool isSuccess) {
custName = _custName;
custLoc = _custLoc;
contractAddress = address(this);
return true;
}
}
//------------------------------------------------------------------------------------
//----- Master
//----- Initialize Customer Master with Customer Name and Total Budget
//------------------------------------------------------------------------------------
contract Master {
address public masterContractAddress;
bytes32 public masterName = "";
Template myCustTemp;
function Master () {
masterContractAddress = address(this);
}
function updateOwnerName (bytes32 _masterName) {
masterName = _masterName;
}
function createCustomer (bytes32 _custName, bytes32 _custLoc) returns (bool flag) {
Template myCust = new Template();
if (myCust.AssignCustomerAttributes(_custName, _custLoc)) {
return true;
} else return false;
}
}
Вам необходимо предоставить все аргументы, необходимые для родительского класса. Из документов Solidity здесь ,
Производные контракты должны предоставлять все аргументы, необходимые для базовых конструкторов.
Таким образом, главный конструктор будет выглядеть так:
function Master (bytes32 _ownerName, bytes32 _loc) CustomerTemplate(_ownerName, _loc) {
owner = msg.sender;
ownerName = _ownerName;
}
CustomerTemplate()
прежнему выдает "Этот контракт не реализует все функции"Я была такая же проблема. Это может произойти, если вы используете наследование.
Исправление довольно тривиальное. Рядом с кнопкой «Создать» в Remix (он же Browser-Solidity) есть раскрывающийся список. Вам просто нужно выбрать фактическую реализацию контракта для развертывания, а не интерфейс.
Ачала Диссанаяке
пользовательDSSR
Ачала Диссанаяке
пользовательDSSR
Ачала Диссанаяке
пользовательDSSR
Роб Хитченс
contractAddress
это необходимо. Нужно знать,contractAddress
чтобы вызвать функцию получения. Если кто-то знает, почему они спрашивают?пользовательDSSR