0

How do I send GoerliETH from one wallet to considering I have my Wallet Address, Private Key, Infura Goerli API Key and the recipient Wallet Address.

I have tried to get balanceOf for the wallet so far, and that works with the following code I found elsewhere :

import web3swift
import BigInt

 struct Wallet {
            let address: String
            let data: Data
            let name: String
            let isHD: Bool
        }

        struct HDKey {
            let name: String?
            let address: String
        }
        let password = "SOME_PASSWORD"
        let key = "MY_PRIVATE_KEY" // Some private key
        let formattedKey = key.trimmingCharacters(in: .whitespacesAndNewlines)
        let dataKey = Data.fromHex(formattedKey)!
        let keystore = try! EthereumKeystoreV3(privateKey: dataKey, password: password)!
        let name = "MY_WALLET_NAME"
        let keyData = try! JSONEncoder().encode(keystore.keystoreParams)
        let address = keystore.addresses!.first!.address
        let wallet = Wallet(address: address, data: keyData, name: name, isHD: false)
        let data = wallet.data
        let keystoreManager: KeystoreManager
        if wallet.isHD {
            let keystore = BIP32Keystore(data)!
            keystoreManager = KeystoreManager([keystore])
        } else {
            let keystore = EthereumKeystoreV3(data)!
            keystoreManager = KeystoreManager([keystore])
        }
        
        let endpoint = "https://goerli.infura.io/v3/MY_API"
        let web3 = web3(provider: Web3HttpProvider(URL(string: endpoint)!)!)

    web3.addKeystoreManager(keystoreManager)
    let coldWalletAddress = EthereumAddress("0xMY_WALLET_ADDRESS")!
    
    let walletAddress = EthereumAddress(wallet.address)! //
    
        web3.transactionOptions.from = walletAddress
        web3.transactionOptions.chainID = 5
        let balanceResult = try! web3.eth.getBalance(address: walletAddress)
        let balanceString = Web3.Utils.formatToEthereumUnits(balanceResult, toUnits: .eth, decimals: 3)!

I now wish to figure out how I can transfer some of this ETH into another wallet further after this code. I understand this process might require me to create a transaction, sign it with my key and then broadcast this transaction... I just don't know how to. Hoping to get a clear example as an answer!

  • Question isn't about the code And make an attempt? Man ..talk about being judgemental in the community. Granted I found certain bits of this on the internet, but as a beginner I tried several minor things to get even this to work. As for not being about the code, I wanted to mention the approach with which the wallet was initialized and wanted to understand how to then make the transaction with this itself. I searched far and hard and could not find any relevant documentation that I could understand myself, and even sat with some student grad students who were unable to solve this for swift – CreatineA Dec 20 '22 at 09:28
  • Either case, I attempted `let balanceSend = try! web3.eth.sendTransaction(, transactionOptions: options, password:"PASSWORD")` But I don't know how exactly to define Ethereum transaction, and additionally Sure it wouldn't work because the transaction must be signed before sending. web3js has a signTransaction function, I just do not know how it works in web3swift because I am unable to find any relevant documentation for it. Only looking for a tiny snippet that can explain how this works, and hopefully do not wish to come off as expecting a "free coding service" – CreatineA Dec 20 '22 at 09:33

0 Answers0