TL;DR I'm very confused by the Contract API in web3: https://web3js.readthedocs.io/en/v1.2.6/web3-eth-contract.html
myContract.methods not available in geth console either with Geth 1.9.11-stable and 1.9.12-unstable on Ubuntu 16.0.4 (fast sync'd)
Is that a version issue? Do I have to come back to a previous version to have this feature?
IN MORE DETAIL I'm currently trying to use this API from my geth console to retrieve the encoded transaction string, to be signed and submitted
When I use on Remix (remix.ethereum.org), after I've compiled the SimpleStorage contract and deployed to Ropsten, I can access the methods as below
On Remix console:> abi = [{"constant": false,"inputs": [{"name": "x","type": "uint256"}],"name": "set","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"},{"constant": true,"inputs": [],"name": "get","outputs": [{"name": "","type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"}]
> mySimpleStorage = new web3.eth.Contract(abi)
> mySimpleStorage.methods
{
"set": "function () { [native code] }",
"0x60fe47b1": "function () { [native code] }",
"set(uint256)": "function () { [native code] }",
"get": "function () { [native code] }",
"0x6d4ce63c": "function () { [native code] }",
"get()": "function () { [native code] }"
}
> tx = mySimpleStorage.methods.set("x")
> tx.encodeABI()
0x60fe47b10000000000000000000000000000000000000000000000000000000000000005
That is what I expect based on documentation
With Geth console:The web3.eth.Contract (uppercase) don't even exist:
> mySimpleStorage = new web3.eth.Contract(abi)
TypeError: Value is not an object: undefined
at <eval>:1:19(5)
I've to use web3.eth.contract (lowercase):
> mySimpleStorage = new web3.eth.contract(abi)
{
abi: [{
constant: false,
inputs: [{...}],
name: "set",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
}, {
constant: true,
inputs: [],
name: "get",
outputs: [{...}],
payable: false,
stateMutability: "view",
type: "function"
}],
eth: {},
at: function(address, callback),
getData: function(),
new: function()
}
Anyway the methods property is missing and it is impossible to call encodeABI()
> tx = mySimpleStorage.methods
Undefined
> tx
undefined