这是我正在尝试的可靠代码。代码的编译工作正常。但是,当我通过 javascript 调用函数 send() 时,它会抛出异常: 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;
}
}
这是javascript代码
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())
}
}
});
每当代码运行时,它都会抛出无效地址错误并崩溃。