2017-12-14 16 views
0

私は契約書の所有権をtestrpcを使ってあるアドレスから別のアドレスに移すためにdappを作成しています。しかし、私はこの問題に直面しています。私はこの所有権の変更を行うために、送信されたメソッドを使用してみました。おそらく私は間違った方法で交換を呼び出すでしょう。 ソリディティバージョン0.4.4 web3 "バージョン": "0.20.2" はまだのようTransfer ownership 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 

Javascriptが所有

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

の転送を実行するために、私はあなたのコード内の任意の特定のミスが表示されません。フロント側のフォーマットが間違っているかもしれませんが、ここに部分的な正面があるので、確かに推測できません。

私はそれがいくつかの助けになるか分かりませんが、時にはtruffleを使って、testrpc/ganache-cliから悪いオペコードを返すいくつかの関数を持っていることが分かりました。

スマートコントラクトを再コンパイルして新しいABIを取得し、契約を再デプロイすると、問題が解決されました。

+0

この問題を解決するにはプライベートネットワークに導入してみましたか?これはtestrpcの固有の問題ですか? –

+0

私はいつもローカルのプライベートネットワーク上にテストネットワーク上に展開し、コードは完全にテストされた後、メインネットに展開します。 プライベートローカルネットワークに展開するとき、私が得て話していたオペコードのエラーは普通でした。私はそれがtestrpcか失敗したABIかどうかわからないが、ABIを削除し、トリュフでコンパイルしてファイルを再生成することで問題は解決した。 – Asone

関連する問題