Api
Asset API
Asset registry and token management
The Asset API provides access to the asset registry and token management functionality.
Endpoints
Get Assets
Get all registered assets for a specific network.
Service: AssetServiceMethod: GetAssets
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
network | Network | YES | Network to query assets for |
Response:
| Field | Type | Description |
|---|---|---|
assets | Asset[] | Array of registered assets |
Asset Object:
| Field | Type | Description |
|---|---|---|
id | string | Asset identifier |
name | string | Asset name |
symbol | string | Asset symbol |
decimals | uint32 | Number of decimal places |
is_native | bool | Whether this is the network's native asset |
Example Request:
TypeScript
const assets = await hydraGrpcClient.getAssets({
protocol: Protocol.EVM,
id: '11155111' // Ethereum Sepolia
})
Rust
let request = tonic::Request::new(GetAssetsRequest {
network: Some(Network {
protocol: Protocol::Evm as i32,
id: "11155111".to_string(),
}),
});
let response = client.get_assets(request).await?;
let assets = response.into_inner().assets;
Get Asset
Get information about a specific asset.
Service: AssetServiceMethod: GetAsset
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
network | Network | YES | Network the asset is on |
asset_id | string | YES | Asset identifier |
Response:
| Field | Type | Description |
|---|---|---|
asset | Asset | Asset details |
Example Request:
TypeScript
const asset = await hydraGrpcClient.getAsset({
network: {
protocol: Protocol.EVM,
id: '11155111'
},
assetId: '0x...' // USDC contract address
})
Rust
let request = tonic::Request::new(GetAssetRequest {
network: Some(Network {
protocol: Protocol::Evm as i32,
id: "11155111".to_string(),
}),
asset_id: "0x...".to_string(),
});
let response = client.get_asset(request).await?;
let asset = response.into_inner().asset;
Get Native Asset
Get the native asset for a network (e.g., BTC for Bitcoin, ETH for Ethereum).
Service: AssetServiceMethod: GetNativeAsset
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
network | Network | YES | Network to get native asset for |
Response:
| Field | Type | Description |
|---|---|---|
asset | Asset | Native asset details |
Example Request:
TypeScript
const nativeAsset = await hydraGrpcClient.getNativeAsset({
protocol: Protocol.BITCOIN,
id: '0a03cf40' // Bitcoin Signet
})
// Returns BTC asset info
Rust
let request = tonic::Request::new(GetNativeAssetRequest {
network: Some(Network {
protocol: Protocol::Bitcoin as i32,
id: "0a03cf40".to_string(),
}),
});
let response = client.get_native_asset(request).await?;
let asset = response.into_inner().asset;
Add Token
Register a new token to the asset registry.
Service: AssetServiceMethod: AddToken
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
network | Network | YES | Network the token is on |
token_address | string | YES | Token contract address (EVM) or asset ID |
Response:
| Field | Type | Description |
|---|---|---|
asset | Asset | Added asset details |
Example Request:
TypeScript
// Add USDC token on Ethereum Sepolia
const asset = await hydraGrpcClient.addToken({
network: {
protocol: Protocol.EVM,
id: '11155111'
},
tokenAddress: '0x...' // USDC contract address
})
Rust
let request = tonic::Request::new(AddTokenRequest {
network: Some(Network {
protocol: Protocol::Evm as i32,
id: "11155111".to_string(),
}),
token_address: "0x...".to_string(),
});
let response = client.add_token(request).await?;
let asset = response.into_inner().asset;
Common Patterns
Get all assets including native
Rust
async fn get_all_network_assets(
client: &mut AssetServiceClient<Channel>,
network: Network,
) -> Result<Vec<Asset>, Box<dyn std::error::Error>> {
let response = client
.get_assets(GetAssetsRequest {
network: Some(network),
})
.await?;
Ok(response.into_inner().assets)
}
Error Handling
| Error Code | Description | Solution |
|---|---|---|
INVALID_ARGUMENT | Invalid network or asset ID | Verify parameters |
NOT_FOUND | Asset not found | Check asset exists on this network |
ALREADY_EXISTS | Token already registered | Use GetAsset instead |
Best Practices
- Cache asset info - Asset details don't change frequently
- Verify token contracts - Always verify token addresses before adding
- Check decimals - Different tokens have different decimal places
- Native asset first - Get native asset info for proper fee calculation