Skip to content

Commit 5f95a78

Browse files
author
Denislav Lazarov
committed
Add Ethereum functions
1 parent bac088b commit 5f95a78

File tree

3 files changed

+933
-5
lines changed

3 files changed

+933
-5
lines changed

index.js

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,238 @@ class CryptoAPIs {
479479

480480
return this.deleteRequest('/bc/btc/' + network + '/hooks/' + webhookID);
481481
}
482+
483+
getEthereumInfo(network) {
484+
485+
return this.getRequest('/bc/eth/' + network + '/info');
486+
}
487+
488+
getEthereumBlock(network, block) {
489+
490+
return this.getRequest('/bc/eth/' + network + '/blocks/' + block);
491+
}
492+
493+
getEthereumLatestBlock(network) {
494+
495+
return this.getRequest('/bc/eth/' + network + '/blocks/latest');
496+
}
497+
498+
getEthereumAddressBalance(network, address) {
499+
500+
return this.getRequest('/bc/eth/' + network + '/address/' + address + '/balance');
501+
}
502+
503+
getEthereumAddressInfo(network, address) {
504+
505+
return this.getRequest('/bc/eth/' + network + '/address/' + address);
506+
}
507+
508+
getEthereumAddressTransactions(network, address, index = 0, limit = 50) {
509+
510+
return this.getRequest('/bc/eth/' + network + '/address/' + address + '/transactions?index=' + index + '&limit=' + limit);
511+
}
512+
513+
generateEthereumAddress(network) {
514+
515+
return this.postRequest('/bc/eth/' + network + '/address', {});
516+
}
517+
518+
generateEthereumAccount(network, password) {
519+
520+
return this.postRequest('/bc/eth/' + network + '/account', {
521+
password: password
522+
});
523+
}
524+
525+
getEthereumTransaction(network, txHash) {
526+
527+
return this.getRequest('/bc/eth/' + network + '/txs/hash/' + txHash);
528+
}
529+
530+
getEthereumTransactionsByBlock(network, block, index = 0, limit = 50) {
531+
532+
return this.getRequest('/bc/eth/' + network + '/txs/block/' + block + '?index=' + index + '&limit=' + limit);
533+
}
534+
535+
getEthereumTransactionByIndexInBlock(network, block, index) {
536+
537+
return this.getRequest('/bc/eth/' + network + '/txs/block/' + block + '/' + index);
538+
}
539+
540+
createEthereumTransaction(network, from, to, gasPrice, gasLimit, value, password) {
541+
542+
return this.postRequest('/bc/eth/' + network + '/txs/new', {
543+
fromAddress: from,
544+
toAddress: to,
545+
gasPrice: gasPrice,
546+
gasLimit: gasLimit,
547+
value: value,
548+
password: password
549+
});
550+
}
551+
552+
createEthereumTransactionWithPrivateKey(network, from, to, gasPrice, gasLimit, value, privateKey) {
553+
554+
return this.postRequest('/bc/eth/' + network + '/txs/new-pvtkey', {
555+
fromAddress: from,
556+
toAddress: to,
557+
gasPrice: gasPrice,
558+
gasLimit: gasLimit,
559+
value: value,
560+
privateKey: privateKey
561+
});
562+
}
563+
564+
sendEthereumTransaction(network, from, to, value) {
565+
566+
return this.postRequest('/bc/eth/' + network + '/txs/send', {
567+
fromAddress: from,
568+
toAddress: to,
569+
value: value
570+
});
571+
}
572+
573+
pushEthereumTransaction(network, signedTx) {
574+
575+
return this.postRequest('/bc/eth/' + network + '/txs/push', {
576+
signed_tx: signedTx
577+
});
578+
}
579+
580+
estimateEthereumTransactionGas(network, from, to, value, data = null) {
581+
582+
var body = {
583+
fromAddress: from,
584+
toAddress: to,
585+
value: value
586+
};
587+
588+
if (data) {
589+
body['data'] = data;
590+
}
591+
592+
return this.postRequest('/bc/eth/' + network + '/txs/gas', body);
593+
}
594+
595+
estimateEthereumSmartContractGas(network) {
596+
597+
return this.getRequest('/bc/eth/' + network + '/contracts/gas');
598+
}
599+
600+
deployEthereumSmartContract(network, privateKey, from, gasPrice, gasLimit, byteCode) {
601+
602+
return this.postRequest('/bc/eth/' + network + '/contracts', {
603+
privateKey: privateKey,
604+
fromAddress: from,
605+
gasPrice: gasPrice,
606+
gasLimit: gasLimit,
607+
byteCode: byteCode
608+
});
609+
}
610+
611+
getEthereumAddressTokenBalance(network, address, contract) {
612+
613+
return this.getRequest('/bc/eth/' + network + '/tokens/' + address + '/' + contract + '/balance');
614+
}
615+
616+
ethereumTransferTokens(network, fromAddress, toAddress, contract, gasPrice, gasLimit, token, password = null, privateKey = null) {
617+
618+
var body = {
619+
fromAddress: fromAddress,
620+
toAddress: toAddress,
621+
contract: contract,
622+
gasPrice: gasPrice,
623+
gasLimit: gasLimit,
624+
token: token
625+
};
626+
627+
if (password) {
628+
629+
body['password'] = password;
630+
} else {
631+
body['privateKey'] = privateKey;
632+
}
633+
634+
return this.postRequest('/bc/eth/' + network + '/tokens/transfer', body);
635+
}
636+
637+
ethereumCreatePayment(network, fromAddress, toAddress, callbackURL, password = null, privateKey = null) {
638+
639+
var body = {
640+
fromAddress: fromAddress,
641+
toAddress: toAddress,
642+
callBack: callbackURL
643+
};
644+
645+
if (password) {
646+
647+
body['password'] = password;
648+
} else {
649+
body['privateKey'] = privateKey;
650+
}
651+
652+
return this.postRequest('/bc/eth/' + network + '/payments', body);
653+
}
654+
655+
ethereumDeletePayment(network, uuid) {
656+
657+
return this.deleteRequest('/bc/eth/' + network + '/payments/' + uuid);
658+
}
659+
660+
ethereumListPayment(network) {
661+
662+
return this.getRequest('/bc/eth/' + network + '/payments');
663+
}
664+
665+
ethereumListPaymentHistory(network) {
666+
667+
return this.getRequest('/bc/eth/' + network + '/payments/history');
668+
}
669+
670+
ethereumCreateUnconfirmedTransactionWebHook(network, callbackURL) {
671+
672+
return this.postRequest('/bc/eth/' + network + '/hooks', {
673+
event: 'UNCONFIRMED_TX',
674+
url: callbackURL
675+
});
676+
}
677+
678+
ethereumCreateConfirmedTransactionWebHook(network, callbackURL, transaction, confirmations) {
679+
680+
return this.postRequest('/bc/eth/' + network + '/hooks', {
681+
event: 'CONFIRMED_TX',
682+
url: callbackURL,
683+
confirmations: confirmations,
684+
transaction: transaction
685+
});
686+
}
687+
688+
ethereumCreateNewBlockWebHook(network, callbackURL) {
689+
690+
return this.postRequest('/bc/eth/' + network + '/hooks', {
691+
event: 'NEW_BLOCK',
692+
url: callbackURL
693+
});
694+
}
695+
696+
ethereumCreateAddressTransactionWebHook(network, callbackURL, address) {
697+
698+
return this.postRequest('/bc/eth/' + network + '/hooks', {
699+
event: 'ADDRESS',
700+
address: address,
701+
url: callbackURL
702+
});
703+
}
704+
705+
ethereumListAllWebHooks(network) {
706+
707+
return this.getRequest('/bc/eth/' + network + '/hooks');
708+
}
709+
710+
ethereumDeleteWebHook(network, webhookID) {
711+
712+
return this.deleteRequest('/bc/eth/' + network + '/hooks/' + webhookID);
713+
}
482714
}
483715

484716
module.exports = CryptoAPIs;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cryptoapis.io",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Crypto APIs SDK",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)