2017-12-14 12 views
0

나는 testrpc를 사용하여 계약의 소유권을 한 주소에서 다른 주소로 이전하기 위해 dapp를 만듭니다. 그러나이 문제가 계속 발생합니다. 이 소유권 변경을 수행하기 위해 전송 방법을 사용하여 시도했습니다. 아마도 잘못된 방식으로 교환을 호출 할 것입니다. 견고 버전 0.4.4 web3 "버전": "0.20.2"아직 같은이전 소유권 web3

web3.js:3127 Uncaught Error: VM Exception while processing transaction: invalid opcode 
at Object.InvalidResponse (web3.js:3127) 
at RequestManager.send (web3.js:6332) 
at Eth.send [as sendTransaction] (web3.js:5066) 
at SolidityFunction.sendTransaction (web3.js:4122) 
at SolidityFunction.execute (web3.js:4208) 
at transferOwnership (luxcure_manu.html:309) 
at HTMLButtonElement.onclick (luxcure_manu.html:378 

전체 견고 계약.

pragma solidity ^0.4.4; 

    // TODO: Hash of the cert through IPFS Hash 
    // Transfer ownership of smart contract 
contract LuxSecure { 
address public contract_owner;   //Manufacturer/owner 
//string public current_owner; //Current Owner of good 
bytes32 public model;   //Model 
mapping(uint => address) public owners; //list of owners 
uint256 public owners_count; 
bytes32 public status;   // (Public(Owned by no one), Private(Bought by another entity),stolen(Stolen from public or private)) 
bytes32 public date_manufactured; //Time 

// Set manufacturer of the Good RUN ONCE ONLY 
function manufacturer() public{ 
    if(owners_count == 0){ 
    contract_owner = msg.sender; 
} 
} 

//Modifier that only allows owner of the bag to Smart Contract AKA Good to use the function 
modifier onlyOwner(){ 
    require(msg.sender == contract_owner); 
    _; 
} 
// Add a new product to the blockchain with a new serial 
function addNewGoods(bytes32 _model,bytes32 _status, bytes32 _date_manufactured) public returns(bool made) {//Declare Goods struct 
setOwner(msg.sender); 
model = _model; 
status = _status; 
date_manufactured = _date_manufactured; 
return true; 
} 

//This function transfer ownership of contract from one entity to another 
function transferOwnership(address _newOwner) public onlyOwner(){ 
    require(_newOwner != address(0)); 
    contract_owner = _newOwner; 
} 

//Set the KEY to uint256 and VALUE owner Ethereum Address 
function setOwner(address owner)public{ 
    owners_count += 1 ; 
    owners[owners_count] = owner; 
} 

//Get the previous owner in the mappings 
function previousOwner()constant public returns(address){ 
    if(owners_count != 0){ 
    uint256 previous_owner = owners_count - 1; 
    return owners[previous_owner]; 
} 
} 

// Getter Methods 
function getManufacturer() constant public returns(address){ 
    return contract_owner; 
} 

function getCurrentOwner() constant public returns(address){ 
    return owners[owners_count] ; 
} 

function getOwnerCount() constant public returns(uint256){ 
    return owners_count; 
} 

function getModel() constant public returns(bytes32){ 
    return model; 
} 

function getStatus() constant public returns(bytes32){ 
return status; 
} 

function getDateManufactured() constant public returns(bytes32){ 
    return date_manufactured; 
} 

}// end of LuxSecure 

자바 스크립트 내가 코드에서 특정 실수가 표시되지 소유권

function transferOwnership(){ 
var account_to_transfer = document.getElementById("ethereumaddress").value; 
contract.transferOwnership(account_to_transfer,{ 
    from:web3.eth.accounts[0], 
    gas:4000000 
}); 
} 
+0

전체 계약을 게시 할 수 있습니까? 또한, 어떤 버전의 web3js를 사용하고 있습니까? –

+0

계약 및 web3js에 대한 추가 정보를 –

답변

0

의 전송을 수행 할 수 있습니다. 앞면에 잘못된 서식이있을 수 있지만 부분적으로 앞면이 나올 때 짐작할 수 없습니다.

내가 도움이 될지 모르지만 때로는 트러플을 사용하여 나에게 testrpc/ganache-cli에서 잘못된 opcode를 반환하는 일부 기능을 사용하게되었습니다. 명백한 오류는 코드에 없었습니다.

스마트 계약을 다시 컴파일하여 새로운 ABI를 얻은 다음 계약을 다시 배포하면 문제가 해결됩니다.

+0

에 추가했습니다.이 문제를 해결하기 위해 개인 네트워크에 배치를 시도 했습니까? 이것은 testrpc의 고유 한 문제점입니까? –

+0

필자는 항상 로컬 사설 네트워크에 먼저 배포 한 다음 테스트 넷에서 코드를 완전히 테스트 한 후 주 네트에 배포합니다. 비공개 로컬 네트워크에 배포 할 때 오피 코드 오류가 발생하는 것은 일반적이었습니다. testrpc 나 ABI가 실패했는지는 모르지만 ABI를 삭제하고 트러 플 컴파일로 파일을 다시 생성하면 문제가 해결됩니다. – Asone