yenom / BitcoinKit

Bitcoin protocol toolkit for Swift
MIT License
842 stars 262 forks source link

Missing arguments for parameters 'bip', 'logger' in call #278

Closed SurpriseMF3000 closed 2 years ago

SurpriseMF3000 commented 2 years ago

Hello, i want to do a Bitcoin swift transaction using BitcoinKit.swift but have a error. I setuped and installed everything using pod install.

The error: "Missing arguments for parameters 'bip', 'logger' in call" (line: let bitcoinKit = BitcoinKit(with...)

The transaction:

    func BTCTransaction(){

        let words = [...]

        let bitcoinKit = BitcoinKit(withWords: words, walletId: "bitcoin-wallet-id", syncMode: .api, networkType: .mainNet)

        bitcoinKit.start()

        bitcoinKit.balance

        bitcoinKit.stop()

    }

Environment

Thank for help and solutions!

mor2vin commented 2 years ago

Have you solved this problem?

SurpriseMF3000 commented 2 years ago

Do you have any issues regarding to this?

mor2vin commented 2 years ago

No, I'm facing a similar problem. I thought maybe you have already found a solution?

mor2vin commented 2 years ago

Can you help me?

SurpriseMF3000 commented 2 years ago

I will try to help you later;)

mor2vin commented 2 years ago

You mean not today? Let me know when you're ready to help.

SurpriseMF3000 commented 2 years ago

Today

mor2vin commented 2 years ago

Ok

SurpriseMF3000 commented 2 years ago
  1. Try to build everything like in the Readme.md
  2. Use Native Modules like JS and then call the JS function which contains your BTC Function from Swift

Notice: This library is over 4-5 years old without any updates so its kind of outdated

mor2vin commented 2 years ago

I'm a newbie. I didn't understand anything)

mor2vin commented 2 years ago

can you tell me more?

SurpriseMF3000 commented 2 years ago

Opportunity 1. You try to build everything like in the documentation of this library. (Readme.md in Root of this project)

Opportunity 2. You use Native modules to call a Bitcoin JS function in Swift. Explantation: you found a working Bitcoin function in a different Programming language like JavaScript. You still want to use Swift as your primary programming language. With Native Modules can you call a JS (can be any language if supported) Function in Swift.

mor2vin commented 2 years ago

I don't know). I want everything to work). I need a module that accepts seed and returns the current balance.

SurpriseMF3000 commented 2 years ago

Would a Public Key instead of Seed Phrase also be ok?

mor2vin commented 2 years ago

No, only by seed.

SurpriseMF3000 commented 2 years ago

Hello again, use https://github.com/horizontalsystems/bitcoin-kit-ios library instead of this one because it is way more recent to get the Public Key from Seed Phrases. To get the Balance, we use Alamofire (API module for Swift) and the api.blockcypher.com API.

You need to install: bitcoin-kit-ios and Alamofire in your Podfile

      pod 'BitcoinCore.swift'
      pod 'BitcoinKit.swift'
      pod 'Alamofire', '~> 5.6' 
  1. turn Seed Phrases to Public Key:

    func checkbalance(){
    
        print("CheckBalance start");
    
        var bitcoinKit: BitcoinKit
    
        let words = [Seed Phrases example:"special", "verb"] //implement here your seed phrases
    
        let seed = Mnemonic.seed(mnemonic: words)
    
        bitcoinKit = try! BitcoinKit(withWords: words, bip: .bip44, walletId: "bitcoin-wallet-id", syncMode: .api, networkType: .testNet, logger: .none) //if you want to use mainnet change to networkType: .mainNet
    
        bitcoinKit.start()
    
        let PublicKey = bitcoinKit.receiveAddress()
    
        print(PublicKey)
    
        print(bitcoinKit.balance) //would normally print the Balance but doesn't works at the moment
    
        print("BTC session completed!")
    
        bitcoinKit.stop()
    
    }
  2. Because bitcoinKit.balance doesn't works at the moment do we need to use a BTC API to get the Balance

API request via Alamofire Swift and api.blockcypher.com API

Where the address in the Link is, do you need to paste the address from which you want to know the balance. You can do this by pasting a variable in there with the Wallet address.

AF.request("https://api.blockcypher.com/v1/btc/test3/addrs/address/balance").responseJSON { response in
            print(response)

            var WalletResponse = response

            print(WalletResponse)

        }
mor2vin commented 2 years ago

I did everything as you said, but I get a lot of errors. Could you assemble this module into a single file so that everything works.

SurpriseMF3000 commented 2 years ago

Import and setup everything like I told you before. Change the @IBOutlet weak var TextLabel: UILabel! (This is a TextLabel) and @IBAction func SendButton(_ sender: Any) (This is a Button) to your own and enter your mnemonics in the Script.

The ViewController.swift

//
//  ViewController.swift
//  Swift Bitcoin
//
//  Created by SurpriseMF3000 on 07.09.22.
//

import UIKit
import BitcoinKit
import BitcoinCore
import HdWalletKit
import HsToolKit
import RxSwift

import Alamofire

class ViewController: UIViewController {

    @IBOutlet weak var TextLabel: UILabel!

    @IBAction func SendButton(_ sender: Any) {

        checkbalance()

    }

    func checkbalance(){

        print("CheckBalance start");

        var bitcoinKit: BitcoinKit

        let words = [Enter here your mnemonics] //!!!!!!!!!!!!!!!!!!!!!

        let seed = Mnemonic.seed(mnemonic: words)

        bitcoinKit = try! BitcoinKit(withWords: words, bip: .bip44, walletId: "bitcoin-wallet-id", syncMode: .api, networkType: .testNet, logger: .none)

        bitcoinKit.start()

        print(bitcoinKit.receiveAddress())

        var publicKey = bitcoinKit.receiveAddress()

        print("PublicKey: " + publicKey)

        AF.request("https://api.blockcypher.com/v1/btc/test3/addrs/\(publicKey)/balance").responseJSON { response in
            print(response)

            var WalletResponse = response

            print("WalletResponse: " ,WalletResponse)

            let WalletBalance = (WalletResponse.result)

            print("Balance: ", WalletBalance)

        }

        print("BTC session completed!")

        bitcoinKit.stop()

    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

}
mor2vin commented 2 years ago

Thank you, as soon as I have the opportunity to test your code

zhang2676105 commented 1 year ago

端点是怎么申请的,谢谢了