Skip to content

MinterTeam/minter-ios-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Version CI Status Version Platform License Last commit

MinterCore

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

MinterCore is available through CocoaPods. To install

it, simply add the following line to your Podfile:

pod 'MinterCore'

About

This is a pure Swift SDK for working with Minter blockchain

Using MinterAPI

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)

address

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?) -> ())?)
Example
AccountManager.default.address("Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99", with: { (data, err) in
  //["balance": ["MNT":"10000000000"], "transaction_count":0]
})

nonce

Use address method of AccountManager to get nonce

send

Returns the result of sending signed tx.

public func send(tx: String, completion: ((String?, String?, Error?) -> ())?)
Example
TransactionManager.default.send(tx: "Mt...") { (hash, statusText, error) in

}

status

Returns node status info.

public func status(with completion: (([String : Any]?, Error?) -> ())?)

validators

Returns list of active validators.

public func validators(height: Int, with completion: (([[String: Any]]?, Error?) -> ())?)

estimateCoinBuy

Return estimate of buy coin transaction.

public func estimateCoinBuy(fromId: Int, toId: Int, amount: Decimal, completion: ((Decimal?, Decimal?, Error?) -> ())?)

estimateCoinSell

Return estimate of sell coin transaction.

public func estimateCoinSell(fromId: Int, toId: Int, amount: Decimal, completion: ((Decimal?, Decimal?, Error?) -> ())?)

coin info

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?) -> ())?)

block

Returns block data at given height.

public func blocks(height: String = "0", with completion: (([String : Any]?, Error?) -> ())?)

events

Returns events at given height.

public func events(height: String = "0", with completion: (([String : Any]?, Error?) -> ())?)

transaction

Returns transaction info.

public func transaction(hash: String, completion: ((Transaction?, Error?) -> ())?)

candidate

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?) -> ())?)

candidates

Returns list of candidates.

height is optional parameter.

public func candidates(height: String = "0", includeStakes: Bool = false, completion: (([[String : Any]]?, Error?) -> ())?)

estimateTxCommission

Return estimate of transaction.

public func estimateCommission(for rawTx: String, height: String = "0", completion: ( (Decimal?, Error?) -> ())?)

transactions

Return transactions by query.

public func transaction(query: String, completion: (([Transaction]?, Error?) -> ())?)

unconfirmedTransactions

Returns unconfirmed transactions.

public func unconfirmedTransaction(limit: String = "0", completion: (([String : Any]?, Error?) -> ())?)

Using MinterSDK

Sign transaction

Returns a signed tx.

Example
  • 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)
}
Example
  • 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)
Example
  • 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)
Example
  • 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)
Example
  • 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()!)
Example
  • 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
)
Example
  • Sign the Delegate transaction
let tx = DelegateRawTransaction(
  nonce: BigUInt(1),
  chainId: 2,
  gasCoinId: 0,
  publicKey: "Mp91cab56e6c6347560224b4adaea1200335f34687766199335143a52ec28533a5",
  coinId: 0,
  value: BigUInt(1000)
)
Example
  • 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)
Example
  • 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)
Example
  • Sign the RedeemCheck transaction
let tx = RedeemCheckRawTransaction(
  nonce: BigUInt(1),
  chainId: 2,
  gasCoinId: 0,
  rawCheck: <Check data>,
  proof: <Proof Data>)
Example
  • Sign the Unbond transaction
let coinId = 0
let publicKey = "91cab56e6c6347560224b4adaea1200335f34687766199335143a52ec28533a5"
let value = BigUInt(2)
let model = UnbondRawTransactionData(publicKey: publicKey, coinId: coinId, value: value)
Example
  • 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 Minter Check

Example
  • 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")

Minter Wallet

  • 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)

Author

sidorov.panda, ody344@gmail.com

License

MinterCore is available under the MIT license. See the LICENSE file for more info.