Skip to content

Instantly share code, notes, and snippets.

View talfco's full-sized avatar

Felix Kuestahler talfco

View GitHub Profile
version: '2'
services:
db:
image: mariadb
restart: always
volumes:
- c:/Users/talfc/DockerVolumes/nextcloud/mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=gugus
public void run1(String endPoint) {
WsProvider wsProvider = new WsProvider(endPoint);
Promise<ApiPromise> ready = ApiPromise.create(wsProvider);
IRpcFunction.Unsubscribe<Promise> unsubscribeHandler = null;
ready.then( (ApiPromise api) -> {
Promise<IRpcFunction.Unsubscribe<Promise>> invoke = api.rpc().chain().function("subscribeNewHead").invoke(
(IRpcFunction.SubscribeCallback<Header>) (Header header) ->
{
System.out.println("Chain is at block: " + header.getBlockNumber()+" trigger "+count);
private void token2token(String tokenSymbolFrom, String tokenSymbolTo, String tokenQuantity) {
//Suppose we want to convert 100 BAT to DAI tokens, which is a token to token conversion.
// Note that ETH is used as the base pair i.e. BAT -> ETH -> DAI.
Kyber3j kyber3j = Kyber3j.build(new KyberService(KyberService.KYBER_ROPSTEN));
log.info("Connected to Kyber Network: "+KyberService.KYBER_ROPSTEN);
try {
Currencies currencies = kyber3j.currencies().send();
if (!checkForError(currencies) && currencies.existsCurreny(tokenSymbolFrom)
&& currencies.existsCurreny(tokenSymbolTo) ) {
EnabledTokensForWallet tokens = kyber3j.enabledTokensForWallet(credentials.getAddress()).send();
private void token2eth(String tokenSymbol, String tokenQuantity){
Kyber3j kyber3j = Kyber3j.build(new KyberService(KyberService.KYBER_ROPSTEN));
log.info("Connected to Kyber Network: "+KyberService.KYBER_ROPSTEN);
try {
// Check if token is supported
Currencies currencies = kyber3j.currencies().send();
if (!checkForError(currencies) && currencies.existsCurreny(tokenSymbol)) {
EnabledTokensForWallet tokens = kyber3j.enabledTokensForWallet(credentials.getAddress()).send();
if (!checkForError(tokens)){
// Check if wallet is enabled for token
private void eth2token(String tokenSymbol, String tokenQuantity) {
Kyber3j kyber3j = Kyber3j.build(new KyberService(KyberService.KYBER_ROPSTEN));
log.info("Connected to Kyber Network: "+KyberService.KYBER_ROPSTEN);
// ETH2<Token> Swap
try {
// Check if token is supported
Currencies currencies = kyber3j.currencies().send();
log.info("Exists Currency"+tokenSymbol+": " + currencies.existsCurreny(tokenSymbol));
if (!checkForError(currencies) && currencies.existsCurreny(tokenSymbol)) {
// Get buy rates
package net.cloudburo.kyber.tutorial.protocol;
import net.cloudburo.kyber.tutorial.methods.request.GasPriceRange;
import net.cloudburo.kyber.tutorial.methods.request.SingleRate;
import net.cloudburo.kyber.tutorial.methods.response.*;
import org.web3j.protocol.core.Request;
import java.math.BigInteger;
public static void main(String[] args) throws Exception {
Application app = new Application();
log.info(">>> SCENARIO: ETH2TOKEN");
Thread.sleep(3000);
app.eth2token("DAI","2");
log.info(">>> SCENARIO: TOKEN2ETH");
Thread.sleep(3000);
app.token2eth("DAI","1");
log.info(">>> SCENARIO: TOKEN2TOKEN");
Thread.sleep(3000);
@talfco
talfco / Token2ETH.java
Last active July 22, 2019 12:57
Kyber Swap Example: Token2ETH
private void token2eth(String tokenSymbol, String tokenQuantity){
Kyber3j kyber3j = Kyber3j.build(new KyberService(KyberService.KYBER_ROPSTEN));
log.info("Connected to Kyber Network: "+KyberService.KYBER_ROPSTEN);
try {
// Check if token is supported
Currencies currencies = kyber3j.currencies().send();
if (!checkForError(currencies) && currencies.existsCurreny(tokenSymbol)) {
EnabledTokensForWallet tokens = kyber3j.enabledTokensForWallet(credentials.getAddress()).send();
// Check if wallet is enabled for token
String tokenId = currencies.getCurrency(tokenSymbol).getId();
@talfco
talfco / ETH2KNCSwap.java
Last active July 21, 2019 15:37
ETH2KNC Kyber Swap
private void eth2knc() {
Kyber3j kyber3j = Kyber3j.build(new KyberService(KyberService.KYBER_ROPSTEN));
log.info("Connected to Kyber Network: "+KyberService.KYBER_ROPSTEN);
// Buy KNC from ETH
try {
// Check if token is supported
Currencies currencies = kyber3j.currencies().send();
log.info("Exists Currency KNC: " + currencies.existsCurreny("KNC"));
if (!checkForError(currencies) && currencies.existsCurreny("KNC")) {
// Get buy rates
@SpringBootApplication
public class DemoApplication {
Logger logger = LoggerFactory.getLogger(DemoApplication.class);
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean