I am looking for a solution that does not require having the contract solidiity code compiled and deployed. For example, if I want to send approve on WETH on live network from the console, without downloading the Solidity code, compiling it, and deploying it. Since the contract is already deployed, it would make sense to be able to interact with it directly.
The idea is that I can get either the abi code (using getCode(contract_address)), or the json (from etherscan API). And using the abi or json, and the contract_address, I assume I should be able to interact with the contract. But how?
Here is what I tried to do (in Truffle console):
# get json from contract https://api.etherscan.io/api?module=contract&action=getabi&address=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&apikey=xxx
Saved it as ./build/contracts/WETH9.json in my truffle project
var weth_contract = require("./build/contracts/WETH9.json") # seems to work var wethContract= new web3.eth.Contract(JSON.parse(weth_contract.result), "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"); wethContract.totalSupply() # fails # Uncaught TypeError: wethContract.totalSupply is not a function wethContract.methods.totalSupply() # returns lots of stuffs, but I am not sure if this is helping...
I am stuck at this point. How can I check totalSupply, or send approve on WETH from the truffle console?
(I am using web3.version '1.2.1'.)