A few days ago, I answered a question, and I felt it was okay, so I wrote an article to record it. The problem is:
如何用web3py调用闭源合约 | 登链社区 | 技术问答 (learnblockchain.cn)
The transaction mentioned in the question is recorded in Binance Transaction Hash (Txhash) Details | BscScan
First check the transaction record, bscscan cannot parse out the function name, that is, abi is not public.
- Search the signature database on the Internet:
https://www.4byte.directory/signatures/
The search results are as follows: Indicates that there is no abi definition for the upload function 2. Without the abi information of the function, is there no way to call it? of course not! Just finding the definition of the function is equivalent to defining a function pointer, the signature is just the function pointer, the parameters of the function ensure that the call stack does not go wrong, and we have the function signature. 3. Find the function prototype, find the contract Click on the contract address 0x217 this The contract code is not public click bytecode-decompiler, get code like this: Search function signature, get function prototype
def unknownb45112b2(uint256 _param1): # not payable
require calldata.size - 4 >=′ 32
require _param1 == _param1
require ext_code.size(heroContractAddress)
- Build functions with different function names and the same function parameters This function has a return value, just to facilitate the demonstration effect
function greet3(uint256 num) public view returns (string memory) {
return "greet3";
}
Generate the calling interface with your contract When used, address is the contract address
greeter = w3.eth.contract(
address='0xB5816B1C17ce9386019ac42310dB523749F5f2c3',
abi=jsobjs['abi']
)
Then call the method
- Looking at the code of webpy, it is obvious that such a call is not supported.
- Modify the code of webpy yourself to support signature replacement My open source code provides, modified, contract.py
Replace it and use it. There are modification instructions on github. There is an example in the code, a contract provides two functions, the function signature
function greet2(uint256 num) public view returns (string memory) {
return "greet2";
}
function greet3(uint256 num) public view returns (string memory) {
return "greet3";
}
* greet2 function signature '0xf9220889'
* greet3 function signature '0x02d355dc'
greet2
The open source code is at:
daodao2007/e001: call smart contract method without abi file (github.com)
If you need other languages and frameworks, please contact me.