Closed SurpriseMF3000 closed 2 years ago
Have you solved this problem?
Do you have any issues regarding to this?
No, I'm facing a similar problem. I thought maybe you have already found a solution?
Can you help me?
I will try to help you later;)
You mean not today? Let me know when you're ready to help.
Today
Ok
Notice: This library is over 4-5 years old without any updates so its kind of outdated
I'm a newbie. I didn't understand anything)
can you tell me more?
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.
I don't know). I want everything to work). I need a module that accepts seed and returns the current balance.
Would a Public Key instead of Seed Phrase also be ok?
No, only by seed.
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'
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()
}
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)
}
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.
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.
}
}
Thank you, as soon as I have the opportunity to test your code
端点是怎么申请的,谢谢了
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:
Environment
Thank for help and solutions!