{"record":{"id":"c2e07b0d45c9db61","repo":"ethereum/go-ethereum","slug":"cannot-send-value-to-non-payable-function","errorCode":null,"errorMessage":"Cannot send value to non-payable function","messagePattern":"Cannot send value to non-payable function","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"internal/jsre/deps/web3.js","lineNumber":4157,"sourceCode":"            error = e;\n        }\n\n        callback(error, unpacked);\n    });\n};\n\n/**\n * Should be used to sendTransaction to solidity function\n *\n * @method sendTransaction\n */\nSolidityFunction.prototype.sendTransaction = function () {\n    var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });\n    var callback = this.extractCallback(args);\n    var payload = this.toPayload(args);\n\n    if (payload.value > 0 && !this._payable) {\n        throw new Error('Cannot send value to non-payable function');\n    }\n\n    if (!callback) {\n        return this._eth.sendTransaction(payload);\n    }\n\n    this._eth.sendTransaction(payload, callback);\n};\n\n/**\n * Should be used to estimateGas of solidity function\n *\n * @method estimateGas\n */\nSolidityFunction.prototype.estimateGas = function () {\n    var args = Array.prototype.slice.call(arguments);\n    var callback = this.extractCallback(args);\n    var payload = this.toPayload(args);","sourceCodeStart":4139,"sourceCodeEnd":4175,"githubUrl":"https://github.com/ethereum/go-ethereum/blob/6bb0588ad8e7f922e4ad5580f51265a4097af08f/internal/jsre/deps/web3.js#L4139-L4175","documentation":"SolidityFunction.sendTransaction refuses to send a transaction whose payload.value > 0 when the ABI entry for the method was not marked payable (this._payable false). It is a client-side guard against a transaction the EVM would revert anyway, checked before anything is broadcast.","triggerScenarios":"Calling instance.method.sendTransaction({from, value: web3.toWei(1,'ether'), gas}) or the sugar instance.method(..., {value: X}) where the ABI for method lacks 'payable': true. Filtering undefined args then building the payload leaves value > 0 and _payable false, so it throws.","commonSituations":"ABI from an older Solidity version (<0.4.x) where payable is not encoded for fallback, deploying with one ABI artifact and calling with another, or simply forgetting the function is non-payable when testing value transfers.","solutions":["Remove the value field from the transaction options if the function must not receive ether.","If the function should accept ether, mark it payable in Solidity (function foo() payable) and redeploy.","Regenerate/refresh the ABI passed to web3 so it matches the deployed contract.","For plain ether transfer use address.sendTransaction or eth.sendTransaction instead of a contract method."],"exampleFix":"// before\ninstance.buy({from: acct, value: web3.toWei(1, 'ether')}); // ABI not payable\n\n// after\n// Solidity: function buy() public payable\ninstance.buy({from: acct, value: web3.toWei(1, 'ether')});","handlingStrategy":"validation","validationCode":"function callMethod(instance, name, opts) {\n  var abi = instance.abi.filter(function (a) { return a.name === name; })[0];\n  if (opts && opts.value > 0 && !abi.payable) {\n    throw new Error(name + ' is not payable; remove value or mark payable in Solidity');\n  }\n  return instance[name](opts);\n}","typeGuard":"function isPayableMethod(instance, name) {\n  return instance.abi.some(function (a) { return a.name === name && a.payable; });\n}","tryCatchPattern":"try { instance.buy({from: a, value: v}); }\ncatch (e) {\n  if (/non-payable function/.test(e.message)) { /* drop value or redeploy payable */ }\n}","preventionTips":["Check the ABI's payable flag before attaching value to options.","Keep the ABI artifact in sync with the deployed Solidity version."],"tags":["web3","payable","abi","transactions"],"backgroundTag":null,"analyzedSha":"6bb0588ad8e7f922e4ad5580f51265a4097af08f","analyzedAt":"2026-08-15T10:06:53.996Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}