Skip to content
This repository has been archived by the owner on Feb 2, 2020. It is now read-only.

Commit

Permalink
+ new version (add createTx)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sing Painter committed Sep 28, 2018
1 parent 11a8da5 commit 7b60d2f
Show file tree
Hide file tree
Showing 22 changed files with 11,327 additions and 10 deletions.
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![logo_en](https://user-images.githubusercontent.com/2198826/46068471-e44d1900-c181-11e8-99cf-0234839623f5.png)

# [MetaHash](https://metahash.org/) JavaScript library
### Версия 0.1.0
### Версия 0.2.0

------------

Expand All @@ -13,7 +13,9 @@
## Использование
1. Подключить MetaHash JavaScript библиотеку:
```html
<script src="https://epexa.github.io/metahash-js/metahash.js"></script>
<script src="https://epexa.github.io/metahash-js/metahash.min.js"></script>
или через CDN:
<script src="https://cdn.jsdelivr.net/gh/epexa/[email protected]/metahash.min.js"></script>
```
2. Если нужно изменить конфигурацию: адрес ноды, и т.д.:
```js
Expand Down Expand Up @@ -104,6 +106,45 @@ metahash.getTx('23fb8f98f1faecf04c23112ad47bba7b42ff7bcec0cdf22ce231061d02e9ad2c
});
```

- ### createTx
Создание транзакции.

Параметры:
***to***
***value***
***fee***
***nonce***
***data***
***publicKeyHex***
***privateKey***
***youHashAddress***

Пример использования:
```js
metahash.apiUrl = 'http://139.162.42.43:9999';
let publicKeyBase64 = 'MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE8gBrTLUQxXDZQ4f/OpiFWe4dhNbEo11PtFkq/0NgXt+AxGwmiWUhojtI56Hj2H3QpxGZCqrjxldDC4IHzpyVfw=='; // from key.pub
let to = '0x0003f6441039b7f944c82ac62f7c124918e02c203b5820f5ed';
let value = 1000;
let fee = 0;
let nonce = null;
let data = '';
let publicKeyHex = metahash.base64toHex(publicKeyBase64); // convert from base64 to hex
/*
1. openssl ec -in key.pem -noout -text
2. copy "priv" value:
42:d1:ae:22:4c:27:fc:02:a4:bc:43:b9:ec:47:6b:
bd:21:b4:51:69:db:97:35:f9:c6:1d:31:a0:87:21:
04:4f
3. remove symbol ":"
*/
let privateKey = '42d1ae224c27fc02a4bc43b9ec476bbd21b45169db9735f9c61d31a08721044f';
let youHashAddress = '0x009b84f533aa2192456a7e944eb471183abbceafe678a98984';
metahash.createTx(to, value, fee, nonce, data, publicKeyHex, privateKey, youHashAddress, (res, err) => {
if (res) console.log('createTx', res, 'http://mhscan.com/?page=tx&id=' + res.params);
else console.error('createTx', err)
});
```

- ### balanceFormatter
Форматирование баланса в правильный вид.

Expand All @@ -123,6 +164,8 @@ BTC: [3LPVbQ8fu4um4aY16tpeie62kznGJywrai](bitcoin:3LPVbQ8fu4um4aY16tpeie62kznGJy

ETH: [0x230D2C5aE86fFB69C8e6d575aB634f345aE497e5](ethereum:0x230D2C5aE86fFB69C8e6d575aB634f345aE497e5)

MHC: [0x00a1d0f653dd39c33255acac2f5ea4fb3c3ea5795908c3bf05](mhc:0x00a1d0f653dd39c33255acac2f5ea4fb3c3ea5795908c3bf05)

------------

## Контакты:
Expand Down
31 changes: 29 additions & 2 deletions example.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script src="metahash.js"></script>
<script src="metahash.min.js"></script>
<script>
metahash.apiUrl = 'http://172.104.224.65:5795'; // net-dev

// http://venus.mhscan.com/?page=address&id=0x009af1b05f5fa19d7054c0deeab32ecb3b1adac6c7f02b2c0b
metahash.fetchBalance('0x009af1b05f5fa19d7054c0deeab32ecb3b1adac6c7f02b2c0b', (res, err) => {
metahash.fetchBalance('0x0003f6441039b7f944c82ac62f7c124918e02c203b5820f5ed', (res, err) => {
if (res) console.log('fetchBalance', res);
else console.error('fetchBalance', err)
});
Expand All @@ -19,4 +21,29 @@
});

metahash.balanceFormatter(20962350000);


let publicKeyBase64 = 'MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE8gBrTLUQxXDZQ4f/OpiFWe4dhNbEo11PtFkq/0NgXt+AxGwmiWUhojtI56Hj2H3QpxGZCqrjxldDC4IHzpyVfw=='; // from key.pub

metahash.apiUrl = 'http://139.162.42.43:9999'; // ?????????
let to = '0x0003f6441039b7f944c82ac62f7c124918e02c203b5820f5ed';
let value = 1000;
let fee = 0;
let nonce = null;
let data = '';
let publicKeyHex = metahash.base64toHex(publicKeyBase64); // convert from base64 to hex
/*
1. openssl ec -in key.pem -noout -text
2. copy "priv" value:
42:d1:ae:22:4c:27:fc:02:a4:bc:43:b9:ec:47:6b:
bd:21:b4:51:69:db:97:35:f9:c6:1d:31:a0:87:21:
04:4f
3. remove symbol ":"
*/
let privateKey = '42d1ae224c27fc02a4bc43b9ec476bbd21b45169db9735f9c61d31a08721044f';
let youHashAddress = '0x009b84f533aa2192456a7e944eb471183abbceafe678a98984';
metahash.createTx(to, value, fee, nonce, data, publicKeyHex, privateKey, youHashAddress, (res, err) => {
if (res) console.log('createTx', res, 'http://mhscan.com/?page=tx&id=' + res.params);
else console.error('createTx', err)
});
</script>
128 changes: 122 additions & 6 deletions metahash.js

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions metahash.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 7b60d2f

Please sign in to comment.