Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to call methods on existing contract #2499

Closed
russanto opened this issue Mar 13, 2019 · 2 comments
Closed

Not possible to call methods on existing contract #2499

russanto opened this issue Mar 13, 2019 · 2 comments
Labels
Bug Addressing a bug

Comments

@russanto
Copy link

Description

It is not possible to call function on already deployed contracts.

Expected behavior

Creating a contract instance with jsonInterface and address I should be able to call the function on that contract

Actual behavior

Contract instance isn't binded to the contract at that address. Instead if I deploy the contract in the same execution just before calling methods, it works perfectly.

Steps to reproduce the behavior

const Web3 = require('web3');
const web3 = new Web3("ws://127.0.0.1:8546");
var simpleContract = new web3.eth.Contract(jsonInterface, address);
simpleContract.methods.myFunction(params).call().then( do something );

Error Logs

Error: Invalid bytes string given: 0x
at AbiCoder.decodeParameters (./node_modules/web3-eth-abi/dist/web3-eth-abi.cjs.js:64:15)
at AbiCoder.decodeParameter (.node_modules/web3-eth-abi/dist/web3-eth-abi.cjs.js:55:19)
at CallContractMethod.afterExecution (./node_modules/web3-eth-contract/dist/web3-eth-contract.cjs.js:743:28)
at CallContractMethod._callee$ (./node_modules/web3-core-method/dist/web3-core-method.cjs.js:354:35)
at tryCatch (./node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (./node_modules/regenerator-runtime/runtime.js:288:22)
at Generator.prototype.(anonymous function) [as next] (./node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (./node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at _next (./node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
at
at process._tickCallback (internal/process/next_tick.js:188:7)

Versions

  • web3.js: 1.0.0-beta.48
  • nodejs: v8.9.4
  • ethereum node: geth 1.8.22
@nivida
Copy link
Contributor

nivida commented Mar 14, 2019

Could you add the ABI and the bytecode of this contract for testing it?

@russanto
Copy link
Author

russanto commented Mar 14, 2019

ABI
[{"constant":true,"inputs":[{"name":"acc_id","type":"string"}],"name":"query","outputs":[{"name":"amount","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"acc_id","type":"string"},{"name":"amount","type":"int256"}],"name":"open","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]

Bytecode
608060405234801561001057600080fd5b506102e3806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80637c2619291461003b578063906412931461010a575b600080fd5b6100f46004803603602081101561005157600080fd5b810190808035906020019064010000000081111561006e57600080fd5b82018360208201111561008057600080fd5b803590602001918460018302840111640100000000831117156100a257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506101cf565b6040518082815260200191505060405180910390f35b6101cd6004803603604081101561012057600080fd5b810190808035906020019064010000000081111561013d57600080fd5b82018360208201111561014f57600080fd5b8035906020019184600183028401116401000000008311171561017157600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190929190505050610243565b005b600080826040518082805190602001908083835b60208310151561020857805182526020820191506020810190506020830392506101e3565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020549050919050565b806000836040518082805190602001908083835b60208310151561027c5780518252602082019150602081019050602083039250610257565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902081905550505056fea165627a7a7230582063c7a6fdaffceee8781e1fc17d2e3727ed52331e7dfc0939bb0711858ce1ac3b0029

EDIT: May be usefull

pragma solidity >=0.4.22 <0.6.0;

contract simple {
    mapping(string => int) private accounts;

    function open(string memory acc_id, int amount) public {
        accounts[acc_id] = amount;
    }

    function query(string memory acc_id) public view returns (int amount) {
        amount = accounts[acc_id];
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests

2 participants