Contract-Invocation

將帶有值參數的交易發送到合約方法

  • January 25, 2017

這是一個簡單的契約:

pragma solidity ^0.4.0;
contract Test {
   uint public sum;
   function makeRequest(){
     sum += msg.value;
   }
}

這是JS程式碼:

function onLoad(){
   const web3 = window.web3;
   const address = "0x26c5267d77348d2748f075d884c75f1a6274149b";
   const abi = [{"constant":false,"inputs":[],"name":"makeRequest","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"sum","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"}];
   const contract = web3.eth.contract(abi).at(address);

   const txo = {
       from: "0x6Ca2f35Ff53c3764ADD78d52378bbFb41CbEef63",
       value: 10000000000000000
   };
   contract.makeRequest(txo, (error, result) => {});
}

執行 JS 程式碼會導致像這樣的失敗事務。錯誤:

錯誤的跳轉目的地

我錯過了什麼?

我認為問題出在這裡:

"payable":false

嘗試更改您的契約(或其 ABI),使此方法可支付。

引用自:https://ethereum.stackexchange.com/questions/11647