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

Create new contract method. #261

Closed
rachkumar opened this issue Apr 15, 2020 · 1 comment
Closed

Create new contract method. #261

rachkumar opened this issue Apr 15, 2020 · 1 comment

Comments

@rachkumar
Copy link

Hi,
https://ropsten.etherscan.io/address/0x1aa657b495a11838b121d3b3c38f196dba3f814c#code
Above is my smart contract method..

I need to call the method "deposit"....which is located as 4th method..

As am new to the Web3swift and smart contract I cant able to call that method successfully.

What I tried:
My code:

func prepareTransaction() {
DispatchQueue.global().async {
let value: String = "0.1"
let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
let addressFrom: String = "0x4E0d3bb7359C8384bca20................"
guard let ethAddressFrom = EthereumAddress(addressFrom) else {return}

        guard let ethContractAddress = EthereumAddress(contractAddress) else {return}

        let web3 = Web3.InfuraRopstenWeb3() //or any test network
        web3.addKeystoreManager(KeystoreManager.defaultManager)

        var options = TransactionOptions.defaultOptions
        options.from = ethAddressFrom
        options.gasPrice = .manual(BigUInt("200000000"))
        options.gasLimit = .manual(BigUInt("27500"))
        //options.value = amount // or any other value you want to send

        guard let contract = web3.contract(myTestABI, at: ethContractAddress, abiVersion: 2) else {return}
                     
        let transaction = contract.write("deposit", parameters: [ethContractAddress, amount!] as [AnyObject], extraData: Data(), transactionOptions: options)!
        
        do {
            let send = try transaction.send(password: "")
            print("trans res", send.transaction)
        } catch(let err) {
            print("trans err", err)
        }
        
    }
}

ABI I GOT USING THE API: https://api-ropsten.etherscan.io/api?module=contract&action=getabi&address=0x1aa657b495a11838b121d3b3..................

From above API am using the key "result" as string.

@rachkumar
Copy link
Author

There is problem with contract method...Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant