To run the example project, clone the repo, and run pod install
from the Example directory first.
MinterCore is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'MinterCore'
This is a pure Swift SDK for working with Minter blockchain
You can get all valid responses and full documentation at Minter Node Api
Initializing SDK
///Minter SDK initialization
import MinterCore
let nodeUrlString = "https://minter-node-1.testnet.minter.network:8841" // example of a node url
MinterCoreSDK.initialize(urlString: nodeUrlString)
Returns coins list, balance and transaction count (for nonce) of an address.
public func address(_ address: String, height: String = "0", with completion: (([String: Any]?, Error?) -> ())?)
AccountManager.default.address("Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99", with: { (data, err) in
//["balance": ["MNT":"10000000000"], "transaction_count":0]
})
Use address method of AccountManager to get nonce
Returns the result of sending signed tx.
public func send(tx: String, completion: ((String?, String?, Error?) -> ())?)
TransactionManager.default.send(tx: "Mt...") { (hash, statusText, error) in
}
Returns node status info.
public func status(with completion: (([String : Any]?, Error?) -> ())?)
Returns list of active validators.
public func validators(height: Int, with completion: (([[String: Any]]?, Error?) -> ())?)
Return estimate of buy coin transaction.
public func estimateCoinBuy(fromId: Int, toId: Int, amount: Decimal, completion: ((Decimal?, Decimal?, Error?) -> ())?)
Return estimate of sell coin transaction.
public func estimateCoinSell(fromId: Int, toId: Int, amount: Decimal, completion: ((Decimal?, Decimal?, Error?) -> ())?)
Returns information about coin. Note: this method does not return information about base coins (MNT and BIP).
public func info(symbol: String, height: String = "0", completion: ((Coin?, Error?) -> ())?)
Returns block data at given height.
public func blocks(height: String = "0", with completion: (([String : Any]?, Error?) -> ())?)
Returns events at given height.
public func events(height: String = "0", with completion: (([String : Any]?, Error?) -> ())?)
Returns transaction info.
public func transaction(hash: String, completion: ((Transaction?, Error?) -> ())?)
Returns candidate’s info by provided public_key. It will respond with 404 code if candidate is not found.
public func candidate(publicKey: String, height: String = "0", completion: (([String : Any]?, Error?) -> ())?)
Returns list of candidates.
height is optional parameter.
public func candidates(height: String = "0", includeStakes: Bool = false, completion: (([[String : Any]]?, Error?) -> ())?)
Return estimate of transaction.
public func estimateCommission(for rawTx: String, height: String = "0", completion: ( (Decimal?, Error?) -> ())?)
Return transactions by query.
public func transaction(query: String, completion: (([Transaction]?, Error?) -> ())?)
Returns unconfirmed transactions.
public func unconfirmedTransaction(limit: String = "0", completion: (([String : Any]?, Error?) -> ())?)
Returns a signed tx.
- Sign the SendCoin transaction
let sendData = SendCoinRawTransactionData(to: "Mx6b6b3c763d2605b842013f84cac4d670a5cb463d", value:
BigUInt(decimal: 1 * TransactionCoinFactorDecimal)!, coinId: 0).encode()
let rawTransaction = SendCoinRawTransaction(nonce: BigUInt(1), chainId: 2, gasCoinId: 0, data: sendData!)
let mnemonic = "adjust correct photo fancy knee lion blur away coconut inform sun cancel"
let seed = String.seedString(mnemonic)!
let pk = PrivateKey(seed: Data(hex: seed))
guard let key = try! pk.derive(at: 44, hardened: true).derive(at: 60, hardened: true).derive(at: 0, hardened: true).derive(at: 0).derive(at: 0).raw.toHexString()
/// Signing raw transaction
let signedTx = RawTransactionSigner.sign(rawTx: rawTransaction, privateKey: key)!
/// Sending raw transaction
transactionManager.send(tx: "Mt" + signedTx) { (txHash, resultText, error) in
print(txHash)
print(resultText)
print(error)
}
- Sign the SellCoin transaction
let gasCoinId = 0
let nonce = BigUInt(1)
let coinFromId = 0
let coinToId = 1
let value = BigUInt(1)
let minimumValue = BigUInt(0)
let tx = SellCoinRawTransaction(nonce: nonce, chainId: 2, gasCoinId: gasCoinId, coinFromId: coinFromId, coinToId: coinToId, value: value, minimumValueToBuy: minimumValue)
- Sign the SellAllCoin transaction
let gasCoinId = 0
let nonce = BigUInt(1)
let coinFromId = 0
let coinToId = 1
let minimumValue = BigUInt(0)
let tx = SellAllCoinsRawTransaction(nonce: nonce, chainId: 2, gasCoinId: gasCoinId, coinFromId: coinFromId, coinToId: coinToId, minimumValueToBuy: minimumValue)
- Sign the BuyCoin transaction
let gasCoinId = 0
let nonce = BigUInt(1)
let coinFromId = 0
let coinToId = 1
let value = BigUInt(1)
let maximumValue = BigUInt(0)
let tx = BuyCoinRawTransaction(nonce: nonce, chainId: 2, gasCoinId: gasCoinId, coinFromId: coinFromId, coinToId: coinToId, value: value, maximumValueToSell: maximumValue)
- Sign the CreateCoin transaction
let name = "Name"
let symbol = "SYMBOL"
let amount = BigUInt(1000)
let reserve = BigUInt(300000000000000000000000)
let ratio = BigUInt(70)
let maxSupply = BigUInt(1000000000000000)
let data = CreateCoinRawTransactionData(
name: name,
symbol: symbol,
initialAmount: initialAmount,
initialReserve: initialReserve,
reserveRatio: reserveRatio,
maxSupply: maxSupply
)
let tx = CreateCoinRawTransaction(nonce: nonce, chainId: 2, gasCoinId: 0, data: data.encode()!)
- Sign the DeclareCandidacy transaction
let nonce = BigUInt(1)
let gasCoinId = 0
let coinId = 0
let address = "Mx7633980c000139dd3bd24a3f54e06474fa941e16"
let publicKey = "Mp91cab56e6c6347560224b4adaea1200335f34687766199335143a52ec28533a5"
let commission = BigUInt(1)
let stake = BigUInt(2)
let model = DeclareCandidacyRawTransaction(
nonce: nonce,
chainId: 2,
gasCoinId: gasCoinId,
address: address,
publicKey: publicKey,
commission: commission,
coinId: coinId,
stake: stake
)
- Sign the Delegate transaction
let tx = DelegateRawTransaction(
nonce: BigUInt(1),
chainId: 2,
gasCoinId: 0,
publicKey: "Mp91cab56e6c6347560224b4adaea1200335f34687766199335143a52ec28533a5",
coinId: 0,
value: BigUInt(1000)
)
- Sign the SetCandidateOn transaction
let nonce = BigUInt(1)
let gasCoinId = 0
let publicKey = "Mpeadea542b99de3b414806b362910cc518a177f8217b8452a8385a18d1687a80b"
let model = SetCandidateOnlineRawTransaction(nonce: nonce, chainId: 2, gasCoinId: gasCoinId, publicKey: publicKey)
- Sign the SetCandidateOff transaction
let nonce = BigUInt(1)
let gasCoinId = 0
let publicKey = "Mpeadea542b99de3b414806b362910cc518a177f8217b8452a8385a18d1687a80b"
let model = SetCandidateOfflineRawTransaction(nonce: nonce, chainId: 2, gasCoinId: gasCoinId, publicKey: publicKey)
- Sign the RedeemCheck transaction
let tx = RedeemCheckRawTransaction(
nonce: BigUInt(1),
chainId: 2,
gasCoinId: 0,
rawCheck: <Check data>,
proof: <Proof Data>)
- Sign the Unbond transaction
let coinId = 0
let publicKey = "91cab56e6c6347560224b4adaea1200335f34687766199335143a52ec28533a5"
let value = BigUInt(2)
let model = UnbondRawTransactionData(publicKey: publicKey, coinId: coinId, value: value)
- Sign the EditCandidate transaction
let pk = "Mpc5b635cde82f796d1f8320efb8ec634f443e6b533a973570e4b5ea04aa44e96d"
let address1 = "Mxe7ca647d17599d3e83048830fbb2df3726a7d22c"
let address2 = "Mxa8ca647d17599d3e83048830fbb2df3726a7d215"
let model = EditCandidateRawTransaction(nonce: BigUInt(1), chainId: 2, gasCoinId: 0, publicKey: pk, rewardAddress: address1, ownerAddress: address2)
- Create check
let nonce = "1"
let dueBlock = BigUInt(99)
let coinId = 0
let value = BigUInt(1)
let phrase = "123"
let tx = IssueCheckRawTransaction(nonce: nonce, dueBlock: dueBlock, coinId: coinId, value: value, gasCoinId: coinId, passPhrase: phrase)
tx.data = data.encode()!
let result = RawTransactionSigner.sign(rawTx: tx, privateKey: <Private Key>)
- Create proof
let proof = RawTransactionSigner.proof(address: "Mxe7ca647d17599d3e83048830fbb2df3726a7d22c", passphrase: "some pass phrase")
- Generate mnemonic.
let mnemonics = String.generateMnemonicString()
- Get seed from mnemonic.
let res = RawTransactionSigner.seed(from: mnemonic, passphrase: "", language: .english)
- Get private key from seed.
let privateKey = PrivateKey(seed: Data(hex: seed))
let key = try? privateKey
.derive(at: 44, hardened: true)
.derive(at: 60, hardened: true)
.derive(at: 0, hardened: true)
.derive(at: 0)
.derive(at: 0)
- Get public key from private key.
let publicKey = RawTransactionSigner.publicKey(privateKey: privateKey!.raw, compressed: false)!.dropFirst()
- Get Minter address from public key.
let address = RawTransactionSigner.address(publicKey: publicKey)
sidorov.panda, ody344@gmail.com
MinterCore is available under the MIT license. See the LICENSE file for more info.