简体   繁体   中英

Contract throws Invalid address when using send() function in solidity 0.4.6

This is the solidity code that I am trying. Compiling of the code works fine. However, when I call the function send() via javascript it throws exception : throw new Error('invalid address');

pragma solidity ^0.4.6; 
contract Agreement {
   address owner;
   address seller; 
   uint amount; 

   function Agreement(address _seller,uint _amount) {
     owner = msg.sender; seller=_seller; amount=_amount;
   } 

   function send(){
    if (owner.balance < amount) throw;      
    if (seller.balance + amount < seller.balance) throw;
    if(!seller.send(amount))throw;
    } 
}

This is the javascript code

var compiled = web3.eth.compile.solidity(contractRaw);
var contract = web3.eth.contract(compiled.info.abiDefinition);
var nContract = contract.new('0x61e323dcf5e116597d96558a91601f94b1f80396',web3.toWei(10, "ether"),{from:this.web3.eth.coinbase, data: compiled.code, gas: 380000}, function(e, contractDetails){
        if(!e) {

            if(!contractDetails.address) {
                console.log("Contract transaction send: TransactionHash: " + contractDetails.transactionHash + " waiting to be mined...");

            } else {
                console.log("Contract mined! Address: " + contractDetails.address);
                console.log(contractDetails.send())

            }

        }
    });

Whenever the code runs, it throws invalid address error and crashes.

That address in fact exists ( etherscan link ) > , but it's not a contract address. If was, must open like this .

When you deploy your contract to etherium, you must copy the hash resulted on contract creation (transaction hash) and search for it on etherscan. It will open all transaction details, including the created contract hash. Use that hash.

尝试61e323dcf5e116597d96558a91601f94b1f80396 ,而不使用0x

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM