Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EthereumContract with Custom ABI returns nil #342

Closed
SwiftyLimi opened this issue Jul 13, 2021 · 3 comments · Fixed by #348
Closed

EthereumContract with Custom ABI returns nil #342

SwiftyLimi opened this issue Jul 13, 2021 · 3 comments · Fixed by #348
Labels
bug Something isn't working 💸 gitcoin-bounty Earn money by helping with this issue!

Comments

@SwiftyLimi
Copy link
Contributor

SwiftyLimi commented Jul 13, 2021

Problem:
I'm trying to initialize a smart contract uploaded lately on the Ropsten Test Network but without success so far.
Here is the contract: https://ropsten.etherscan.io/address/0x36cC04E8fDb5237EAD5B475089c640834436e61b

Using:
pod 'web3swift' , :git => 'https://github.com/lvyikai/web3swift.git', :branch => 'develop'

Steps to reproduce:

let ropstenContractABI: String = Uniswap.ABI
let ropstenEthereumAddress: EthereumAddress = EthereumAddress(Uniswap.address)!
let ropstenContract = EthereumContract(ropstenContractABI, at: ropstenEthereumAddress)

Where Uniswap.address is:

"0x36cC04E8fDb5237EAD5B475089c640834436e61b"

and Uniswap.ABI is :

"[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"","type":"address"}],"name":"Error","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"Received","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"claimOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum Router.OrderType","name":"orderType","type":"uint8"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint256","name":"assetInOffered","type":"uint256"},{"internalType":"uint256","name":"assetOutExpected","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"executeSwap","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_to","type":"address"}],"name":"feesWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint256","name":"amountIn","type":"uint256"}],"name":"getBestQuote","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"},{"internalType":"bool","name":"direct","type":"bool"},{"internalType":"bool","name":"renounce","type":"bool"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]"

For some reason, the library initializes the Contract when I use the Web3.Utils.erc20ABI, which is :

"[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"version","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"},{"name":"_extraData","type":"bytes"}],"name":"approveAndCall","outputs":[{"name":"success","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"remaining","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"_initialAmount","type":"uint256"},{"name":"_tokenName","type":"string"},{"name":"_decimalUnits","type":"uint8"},{"name":"_tokenSymbol","type":"string"}],"type":"constructor"},{"payable":false,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Approval","type":"event"},]"

Your help would be much appreciated

Thank you in advance for taking the time to read this

@SwiftyLimi SwiftyLimi changed the title Contract with Custom ABI returns nil EthereumContract with Custom ABI returns nil Jul 13, 2021
@SwiftyLimi
Copy link
Contributor Author

Removing {"stateMutability":"payable","type":"receive"} from the contract ABI, allowed me to initialize the contract for some reason !

@skywinder
Copy link
Collaborator

skywinder commented Jul 31, 2021

Thanks for the update. Did you realize, what cause the issue? I would be happy to send bounty for this fix.

@skywinder skywinder added the bug Something isn't working label Jul 31, 2021
@SwiftyLimi
Copy link
Contributor Author

Hi @skywinder. The issue happened when a contract ABI included {"stateMutability":"payable","type":"receive"} on it's body. A type apparently missing on ABI.Element. Hence the parsing error which brought back a nil value.

I added a new receive type at ABI.Element that parses this type.

This ABI element, when present in a contract, indicates that the contract allows to receive tokens through a function call.

@skywinder skywinder added the 💸 gitcoin-bounty Earn money by helping with this issue! label Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 💸 gitcoin-bounty Earn money by helping with this issue!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants