⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

wallet/triggerconstantcontract

Zero-Cost Contract Reads

Dwellir's TRON infrastructure enables instant contract state queries without consuming energy or bandwidth. Read smart contract data in real-time without transaction fees.

Start querying contracts →

Execute smart contract view/pure functions without creating a blockchain transaction. Perfect for reading contract state, calculating values, or retrieving stored data.

Use Cases

wallet/triggerconstantcontract is essential for:

  • Token Balance Queries - Check TRC20 token balances
  • Price Feeds - Read oracle price data
  • Game State - Query game contract states
  • DeFi Positions - Check liquidity pool shares
  • Contract Verification - Test function outputs

Parameters

ParameterTypeRequiredDescription
contract_addressstringYesSmart contract address (Base58 or Hex)
function_selectorstringYesFunction signature (e.g., "balanceOf(address)")
parameterstringNoEncoded function parameters (hex)
owner_addressstringNoAddress calling the function
call_valuenumberNoTRX amount in SUN (for payable functions)
call_token_valuenumberNoTRC10 token amount
token_idnumberNoTRC10 token ID
visiblebooleanNoUse Base58 format (default: true)

Request Example

{
"contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"function_selector": "balanceOf(address)",
"parameter": "000000000000000000000000a614f803b6fd780986a42c78ec9c7f77e6ded13c",
"owner_address": "TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN",
"visible": true
}

Response Fields

FieldTypeDescription
resultobjectExecution result
result.resultbooleanWhether execution succeeded
result.codestringResponse code
result.messagestringError message if failed
energy_usednumberEstimated energy consumption
constant_resultarrayReturn values (hex encoded)
transactionobjectSimulated transaction object

Implementation Examples

# Call TRC20 balanceOf function
curl -X POST "https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/triggerconstantcontract" \
-H "Content-Type: application/json" \
-d '{
"contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"function_selector": "balanceOf(address)",
"parameter": "000000000000000000000000a614f803b6fd780986a42c78ec9c7f77e6ded13c",
"visible": true
}'

# Get token name
curl -X POST "https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/triggerconstantcontract" \
-H "Content-Type: application/json" \
-d '{
"contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"function_selector": "name()",
"visible": true
}'

# Get token symbol
curl -X POST "https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/triggerconstantcontract" \
-H "Content-Type: application/json" \
-d '{
"contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"function_selector": "symbol()",
"visible": true
}'

# Get total supply
curl -X POST "https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/triggerconstantcontract" \
-H "Content-Type: application/json" \
-d '{
"contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"function_selector": "totalSupply()",
"visible": true
}'

# Parse balance result with jq
curl -s -X POST "https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY/wallet/triggerconstantcontract" \
-H "Content-Type: application/json" \
-d '{
"contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"function_selector": "balanceOf(address)",
"parameter": "000000000000000000000000a614f803b6fd780986a42c78ec9c7f77e6ded13c",
"visible": true
}' | jq '{
success: .result.result,
energy_used: .energy_used,
balance_hex: .constant_result[0],
balance_decimal: (.constant_result[0] | ltrimstr("0x") |
if . == "" then "0" else . end |
tonumber | tostring)
}'

# Script to check multiple token balances
#!/bin/bash
API_KEY="YOUR_API_KEY"
USER_ADDRESS_HEX="000000000000000000000000a614f803b6fd780986a42c78ec9c7f77e6ded13c"

TOKENS=(
"TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t:USDT"
"TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR:WTRX"
)

for token_info in "${TOKENS[@]}"; do
IFS=':' read -r addr symbol <<< "$token_info"

echo "Checking $symbol balance..."

response=$(curl -s -X POST \
"https://api-tron-mainnet.n.dwellir.com/$API_KEY/wallet/triggerconstantcontract" \
-H "Content-Type: application/json" \
-d "{
\"contract_address\": \"$addr\",
\"function_selector\": \"balanceOf(address)\",
\"parameter\": \"$USER_ADDRESS_HEX\",
\"visible\": true
}")

balance=$(echo "$response" | jq -r '.constant_result[0]')

if [ "$balance" != "null" ] && [ "$balance" != "" ]; then
# Convert hex to decimal (simplified)
echo " Raw: $balance"
else
echo " Error or zero balance"
fi
echo ""
done

Response Example

Successful Response

{
"result": {
"result": true,
"code": "SUCCESS",
"message": ""
},
"energy_used": 968,
"constant_result": [
"0000000000000000000000000000000000000000000000000000000005f5e100"
],
"transaction": {
"visible": true,
"txID": "abc123...",
"raw_data": {
"contract": [
{
"parameter": {
"value": {
"data": "70a08231000000000000000000000000a614f803b6fd780986a42c78ec9c7f77e6ded13c",
"owner_address": "TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN",
"contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
},
"type_url": "type.googleapis.com/protocol.TriggerSmartContract"
},
"type": "TriggerSmartContract"
}
],
"ref_block_bytes": "7ac7",
"ref_block_hash": "4d9bb8f8c9c59ac3",
"expiration": 1702456849000,
"timestamp": 1702456789000
}
}
}

Failed Response

{
"result": {
"result": false,
"code": "CONTRACT_VALIDATE_ERROR",
"message": "No contract or not a valid smart contract"
}
}

Common Use Cases

1. Token Balance Checker

async function checkTokenBalance(tokenAddress, userAddress) {
const token = new TRC20Contract('API_KEY', tokenAddress);

try {
const [symbol, decimals, balance] = await Promise.all([
token.symbol(),
token.getDecimals(),
token.balanceOf(userAddress)
]);

return {
token: symbol,
balance: balance.formatted,
decimals: decimals,
hasBalance: BigInt(balance.raw) > 0n
};
} catch (error) {
return {
error: 'Failed to fetch token data',
details: error.message
};
}
}

2. DEX Price Monitor

async function monitorDexPrice(poolAddress) {
const getPrice = async () => {
const result = await callContractView(
poolAddress,
'getReserves()'
);

const reserves = parseReserves(result.constant_result[0]);
return calculatePrice(reserves.token0, reserves.token1);
};

return setInterval(async () => {
const price = await getPrice();
console.log(`Current price: ${price}`);
}, 10000); // Check every 10 seconds
}

3. Multi-Call Pattern

async function getCompleteTokenInfo(tokenAddress) {
const functions = [
'name()',
'symbol()',
'decimals()',
'totalSupply()'
];

const results = await Promise.all(
functions.map(fn =>
callContractView(tokenAddress, fn)
)
);

return {
name: decodeString(results[0].constant_result[0]),
symbol: decodeString(results[1].constant_result[0]),
decimals: decodeUint256(results[2].constant_result[0]),
totalSupply: decodeUint256(results[3].constant_result[0])
};
}

Error Handling

Error CodeDescriptionSolution
CONTRACT_VALIDATE_ERRORInvalid contract addressVerify contract exists
OUT_OF_ENERGYInsufficient energy for callAdd energy estimation
REVERTFunction revertedCheck function requirements
INVALID_METHODFunction doesn't existVerify function signature
async function safeContractCall(address, method, params) {
try {
const result = await callContractView(address, method, params);

if (!result.result?.result) {
return {
success: false,
error: result.result?.message || 'Unknown error',
code: result.result?.code
};
}

return {
success: true,
data: result.constant_result?.[0] || '0x',
energyUsed: result.energy_used
};
} catch (error) {
return {
success: false,
error: error.message,
code: 'NETWORK_ERROR'
};
}
}

Best Practices

  1. Cache Results - Cache view function results appropriately
  2. Batch Calls - Group multiple calls for efficiency
  3. Handle Errors - Always check result.result for success
  4. Estimate Energy - Monitor energy_used for optimization
  5. Validate Input - Ensure parameters are properly encoded

Need help? Contact support or visit our TRON documentation.