mega.getFromContract()
Read contract state without creating a transaction. No wallet prompt, no gas — just a routed eth_call-style read.
Signature
mega.getFromContract<T>(request: GetFromContractRequest): Promise<T>
Parameters
Field
Type
Required
Notes
address
`0x${string}`
required
Contract address.
abi
any
required
Contract ABI fragment for the read function.
functionName
string
required
Function to read.
args
any[]
required
Function arguments (use [] for no args).
Example
const balance = await mega.getFromContract<bigint>({
address: '0xTokenAddress',
abi: [{
type: 'function',
name: 'balanceOf',
stateMutability: 'view',
inputs: [{ name: 'owner', type: 'address' }],
outputs: [{ name: '', type: 'uint256' }],
}],
functionName: 'balanceOf',
args: ['0xWalletAddress'],
});Response
Decoded value of type T (the generic you pass).
Notes
For write calls, use callContract(). For known wallet token balances, balances() is faster than calling balanceOf per token.
Last updated