public boolean isValid ( ) throws IOException { if ( contractBinary . equals ( BIN_NOT_PROVIDED ) ) { throw new UnsupportedOperationException ( "Contract binary not present in contract wrapper, " + "please generate your wrapper using -abiFile=<file>" ) ; } if ( contractAddress . equals ( "" ) ) { throw new UnsupportedOperationException ( "Contract binary not present, you will need to regenerate your smart " + "contract wrapper with web3j v2.2.0+" ) ; } EthGetCode ethGetCode = web3j . ethGetCode ( contractAddress , DefaultBlockParameterName . LATEST ) . send ( ) ; if ( ethGetCode . hasError ( ) ) { return false ; } String code = Numeric . cleanHexPrefix ( ethGetCode . getCode ( ) ) ; int metadataIndex = code . indexOf ( "a165627a7a72305820" ) ; if ( metadataIndex != - 1 ) { code = code . substring ( 0 , metadataIndex ) ; } // There may be multiple contracts in the Solidity bytecode, hence we only check for a // match with a subset return ! code . isEmpty ( ) && contractBinary . contains ( code ) ; }
Check that the contract deployed at the address associated with this smart contract wrapper is in fact the contract you believe it is .