Open xiongjiabing opened 7 months ago
It's not clear to me what you mean by "validity" of an address. There are any number of account IDs that have never been funded. Unfunded accounts will not be present in the ledger. But the response to the account_info
RPC command may be able to help with your question.
Suppose you pass account_info
an account ID that looks like it might be valid but is not. You'll get a response that looks like this:
{
"error" : "actMalformed",
"error_code" : 35,
"error_message" : "Account malformed.",
"rpc" : {
"method" : "account_info",
"params" : [ "rw4qSGLshpdo6cvW3ZoeCMFRzVKRz52po" ]
},
"status" : "error"
}
Notice that it says "Account malformed". That's your clue.
On the other hand, if you have an account ID that is valid but has never been funded, then you'll get a response like this:
{
"result" : {
"account" : "r9W1TDGQq1FttGqBCt3PH1YR56oVAgxqLg",
"error" : "actNotFound",
"error_code" : 19,
"error_message" : "Account not found.",
"ledger_current_index" : 85365282,
"request" : {
"account" : "r9W1TDGQq1FttGqBCt3PH1YR56oVAgxqLg",
"api_version" : 1,
"command" : "account_info"
},
"status" : "error",
"validated" : false
}
}
Notice that is says, "Account not found". That means the account ID is well formed, but the account has never been funded so it is not present in the ledger.
@xiongjiabing One more comment that is more Java SDK-focused.
If you're wanting to verify an address using the Java SDK only, you can put the bytes through the binary codec to see if you get the correct result (as you saw in the link your provided).
For example, an invalid base58 address will make the decoder throw an exception:
addressCodec.decodeAccountId(Address.of("rJrRMgiRgrU6hDF4pgu5DXQdWyPbY35Er"));
(Notice that the address above is missing a trailing N
-- it should be rJrRMgiRgrU6hDF4pgu5DXQdWyPbY35ErN
).
That said, the SDK currently doesn't have a this kind of check as a first-class API, e.g., in the Address
class, so if you think that would be valuable to do directly from Java, you could file a request in the Java SDK. But if you're OK simply making an RPC call to a rippled server like @scottschurr showed above, then that will work too.
(Note that my comment here only relates to the question of "is an address well-formed". To see if an account is funded, you have to do what @scottschurr said above, and make an RPC to the network.
hi team, Is there a way to verify the validity of the address?
I see that the corresponding SDK is provided, https://github.com/XRPLF/xrpl4j/blob/main/xrpl4j-core/src/test/java/org/xrpl/xrpl4j/codec/addresses/AddressCodecTest.java
rw4qSGLshpdo6cvW3ZoeCMFRzVKRz52po for example, like this address, it is the correct length and format, but it is not found in the ledger