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

calling a payable function with parameters #2

Closed
ungaro opened this issue Aug 23, 2018 · 5 comments
Closed

calling a payable function with parameters #2

ungaro opened this issue Aug 23, 2018 · 5 comments
Labels
question Further information is requested wait for reply

Comments

@ungaro
Copy link

ungaro commented Aug 23, 2018

i'm struggling to find an example to use a payable function with parameters.

let's say i've an function in my Smart Contract:

    function doSomething(address[] _adresses, address[] _groups, uint[] _percentages)
        public
        payable
        returns(address) {

How do i call this SC and send ethers to it & pass parameters and get the return value?

Thanks.

@shamatar
Copy link
Contributor

Hello @ungaro

First of all you should understand that if the function is mutating (like one above) you are not guaranteed that a return value will in fact be the same when you check for it and when transaction executes.

  1. how to get a return value:
  • encode the parameters into the “TransactionIntermediate”. Please check the various examples in tests
  • use the “call” method on this intermediate and supply required options (Web3Options struct) into the call. One of the field in options is “value” - it’s an amount of Wei (1 ETH = 10^18 wei) attached to the transaction
  • upon execution you will get returned parameters
  1. to send a transaction
  • make an intermediate
  • use the “send” method and supply the options

I recommend you to go through the tests of web3swift to check the examples.

Sincerely, Alex

@blockcowboy
Copy link

Can you give example how to trap error from a send call based on this? Not familiar with the way you have used Result.

guard let tokenNameRes = intermediate?.send(options: options) else {return}
        guard case .failure(let resultError) = tokenNameRes else {
            print(tokenNameRes)
            return}
        guard case .success(let result) = tokenNameRes else {
            print(tokenNameRes)
            return

@shamatar
Copy link
Contributor

shamatar commented Aug 23, 2018

@blockcowboy

You almost have made it right

   let result = intermediate.send()
   switch result {
   case .success(let successResult):
   // this is successful result, use successResult for your activity
   case .failure(let error):
   // work with an error
   }

P.S. Sorry, don’t have markdown on a phone

@skywinder skywinder added the question Further information is requested label Aug 28, 2018
@skywinder
Copy link
Collaborator

@blockcowboy did you solve your task?

@TonioMacaronio
Copy link
Collaborator

It seems that the issue is resolved, so its closed

TonioMacaronio added a commit that referenced this issue Dec 21, 2018
Fixed erc20 precompiled contract
yaroslavyaroslav pushed a commit that referenced this issue Jul 19, 2023
fix: createNewAccount always non-hardened derivation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested wait for reply
Projects
None yet
Development

No branches or pull requests

5 participants