Skip to content

How to call fallback function of a contract? #1524

Answered by zemse
Arul- asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @psytron, if your fallback function returns a value and you directly calling the contract using sendTransaction(tx), then you can't get the return value trivial since it's a transaction (though it could be extracted from an execution trace somehow). If you instead wanted to do a simple read call (to a maybe view or pure function), you can do following:

const result = await provider.call({
    to: contractAddress,
    data: '0x1234..' // encoded data
})

If your proxy contract is a minimal proxy contract like EIP-1167, then you can simply pass the proxy address to the Contract.

const myContract = new ethers.Contract(proxyAddr, implementationAbi, provider);

Replies: 8 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@sachinsinghjagawat
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@qzirak
Comment options

@ricmoo
Comment options

@qzirak
Comment options

Answer selected by ricmoo
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants
Converted from issue

This discussion was converted from issue #182 on April 28, 2021 00:41.