-
Notifications
You must be signed in to change notification settings - Fork 73
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
More examples or better explanation on how to make contract calls #116
Comments
Hi, thank you for the feedback. So, if you have contract ABI then library will generate required wrappers for call and send functions that suits for your contract. As example please check https://github.com/airalab/hs-web3/blob/master/examples/erc20/Main.hs#L17 And here is wrapping module that generates functions from contract ABI: https://github.com/airalab/hs-web3/blob/master/examples/erc20/ERC20.hs |
Thanks for getting back to me @akru, I am aware of this method of making function calls, however, I am unable to do a main = do
result <- runWeb3 $
withAccount () $
withParam -- ... and by extension, only this works for me main = do
result <- runWeb3 $
withAccount (LocalKey ... ) $ -- or Personal, though I am unable to make txs this way
withParam -- ... but it creates a tx when I would like to only make a call/run a getter function. I do not have issues with constants, like in your example when using |
So, https://hackage.haskell.org/package/web3-0.9.1.0/docs/Network-Ethereum-Account.html |
Yes, I've read this doc, but again I am unsure of how to use this With web3.py, web3.js and ethers.js it is: # web3.py
erc20.functions.allowance(owner.address, spender.address).call() // ethers.js
await erc20.allowance(owner.address, spender.address) where Can you provide an example of doing this allowance call in web3-hs? When I use the method in the example, it makes a transaction that is logged in etherscan, which should not happen. |
Generally, developer don’t use call/send functions directly. Developer uses wrappers created for specified contract ABI: template in https://github.com/airalab/hs-web3/blob/master/examples/erc20/ERC20.hs will generate
|
Sorry for the late reply @akru, I have been a bit preoccupied. It turns out the abi was the issue when using the method wrappers. Related to #98, I had to add I mistakenly added Now I have a question about extracting data from its return value. If the return value is a primitive data type, getting the return value is straight forward as the examples show. If the return type is a composite data type such as a struct or an array of structs, then how do you obtain that value? E.g. this is the return type of the method I'm using returnValue :: ((UIntN 256, Text, UIntN 256), UIntN 256, UIntN 256, UIntN 256) if I do something like snd' ((_, _, _), a, _, _) = a then case result of
Left err -> print err
Right info -> putStrLn ("Success: " ++ show(fromEnum $ snd' returnValue)) I get too few bytes
From: demandInput When I do a |
Solidity library in hs-web3 uses Generics to drive abi encoding. https://github.com/airalab/hs-web3/blob/master/packages/solidity/src/Data/Solidity/Abi/Generic.hs This approach applicable as for tuples in your case as same for production type structures (tuple also production type structure). TH wrapper automatically generates function outputs according to contract abi. From other side you can set output type manually for |
Okay, so you're saying that I shouldn't need anything else besides case result of
Left err -> print err
Right info -> print info to get the return value... so I'm doing something wrong. I changed a value in the input of my function and suddenly it started working. However its strange, the logic when I use web3.py and hs-web3 is exactly the same; the input takes in a value of |
Going to close this issue, as you've provided some much needed clarification. Thank you @akru for your help 😄 |
I'm at a total loss as to how make a contract call, and the only way to make a transaction from what I can tell is to use
withAccount
withwithParam
which according to the docs is not the only option.How can you use
call
orsend
? What params are needed? The docs state thatBut what does that mean, how can we set the account context, how do you se the transaction parameters before invoking
call
andsend
?The text was updated successfully, but these errors were encountered: