Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gre4ixin/exchanger
https://github.com/gre4ixin/exchanger
1inch-api blockchain swift
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/gre4ixin/exchanger
- Owner: gre4ixin
- License: mit
- Created: 2022-08-09T09:53:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-21T14:00:57.000Z (about 2 years ago)
- Last Synced: 2024-12-09T02:36:34.879Z (27 days ago)
- Topics: 1inch-api, blockchain, swift
- Language: Swift
- Homepage:
- Size: 124 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Exchange
1Inch exchange api wrapper with async/await swift.
```swift
let exchangeFacade: ExchangeFacade = ExchangeService()// Get tokens info
Task {
let tokens = await exchangeFacade.tokens(blockchain: .polygon)
switch tokens {
case .success(let tokensDTO):
dto.tokens.forEach {
print($0.value)
}
case .failure(let error):
print(error.localizedDescription)
}
}// Generation swap data
Task {
let amount = 1_000_000_000_000_000_000
let fromAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
let toAddress = "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063"
let walletAddress = "0x**..." //Your wallet address
let response = await exchange.swap(blockchain: .polygon,
parameters: SwapParameters(fromTokenAddress: fromAddress,
toTokenAddress: toAddress,
amount: "\(amount)",
fromAddress: walletAddress,
slippage: 1))
switch response {
case .success(let dto):
print(dto.tx.data) // Data for sign and push to blockchain
case .failure(let error):
print(error)
}
}
```Supports **Ethereum**, **Binance smart chain**, **Polygon**, **Optimism**, **Arbitrum**, **Gnosis**, **Avalanche**, **Fantom**, **Klayth**, **Aurora**.