-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,895 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
# harmony-sdk-examples | ||
|
||
# Install | ||
|
||
```bash | ||
yarn install | ||
``` | ||
|
||
|
||
# Test local wallet | ||
|
||
1. open `nodejs` | ||
2. run `node testWallet.js` | ||
3. you can see `mnemonic` and `simple password` and 10 accounts imported | ||
|
||
|
||
# Test with Harmony node | ||
|
||
First you have to run harmony's test node. | ||
|
||
1. git clone | ||
|
||
``` bash | ||
git clone git@github.com:harmony-one/harmony.git | ||
``` | ||
|
||
2. follow the `Build all executables` instruction, [here](https://github.com/harmony-one/harmony/tree/master) | ||
3. open your editor, inside `core/resharding.go` , edit `GenesisShardSize = 50` to `GenesisShardSize = 5` | ||
4. use this script to run | ||
|
||
```bash | ||
./test/deploy.sh ./test/configs/ten-oneshard.txt | ||
``` | ||
|
||
Wait for the test-node running for 30 seconds, | ||
|
||
Then **open another console** , go back to our `nodejs` folder, | ||
|
||
Run: | ||
|
||
``` bash | ||
node testNode.js | ||
``` | ||
|
||
|
||
# Test with `ganache-cli` | ||
** ganache-cli runs in js file **, | ||
|
||
In this case, we use ganache and ethereum's setting to simulate the result | ||
We don't need harmony's testnode running. | ||
1. open `nodejs` | ||
2. run `node testGanache.js` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
pragma solidity ^0.5.1; | ||
|
||
contract Calc { | ||
|
||
uint count; | ||
|
||
function getCount() public returns (uint) { | ||
|
||
return count; | ||
|
||
} | ||
|
||
function add(uint a, uint b) public returns (uint) { | ||
count++; | ||
return a + b; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pragma solidity ^0.5.1; | ||
|
||
|
||
contract MyContract { | ||
function myFunction() public returns(uint256 myNumber, string memory myString) { | ||
return (23456, "Hello!%"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pragma solidity ^0.5.1; | ||
|
||
contract SimpleStorage { | ||
|
||
event ValueChanged(address indexed author, string oldValue, string newValue); | ||
|
||
string _value; | ||
|
||
constructor(string memory value) public { | ||
emit ValueChanged(msg.sender, _value, value); | ||
_value = value; | ||
} | ||
|
||
function getValue() view public returns (string memory) { | ||
return _value; | ||
} | ||
|
||
function setValue(string memory value) public { | ||
emit ValueChanged(msg.sender, _value, value); | ||
_value = value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const { Harmony } = require('@harmony-js/core') | ||
const { ChainID, ChainType } = require('@harmony-js/utils') | ||
|
||
const Settings = { | ||
Ropsten: { | ||
http: 'https://ropsten.infura.io/v3/4f3be7f5bbe644b7a8d95c151c8f52ec', | ||
ws: 'wss://ropsten.infura.io/ws/v3/4f3be7f5bbe644b7a8d95c151c8f52ec', | ||
type: ChainType.Ethereum, | ||
id: ChainID.Ropsten | ||
}, | ||
Rinkeby: { | ||
http: 'https://rinkeby.infura.io/v3/4f3be7f5bbe644b7a8d95c151c8f52ec', | ||
ws: 'wss://rinkeby.infura.io/ws/v3/4f3be7f5bbe644b7a8d95c151c8f52ec', | ||
type: ChainType.Ethereum, | ||
id: ChainID.Ropsten | ||
}, | ||
Ganache: { | ||
http: 'http://localhost:18545', | ||
ws: 'ws://localhost:18545', | ||
type: ChainType.Ethereum, | ||
id: ChainID.Ganache | ||
} | ||
} | ||
|
||
// a function that will map the setting to harmony class constructor inputs | ||
function useSetting(setting, providerType) { | ||
return [setting[providerType], setting.type, setting.id] | ||
} | ||
|
||
// simply change `Ropsten` to `Rinkeby` to test with different testnet | ||
// and switch `ws` or `http` as RPC provider | ||
|
||
const harmony = new Harmony(...useSetting(Settings.Ropsten, 'ws')) | ||
|
||
// import our preset mnes | ||
const mne = | ||
'food response winner warfare indicate visual hundred toilet jealous okay relief tornado' | ||
|
||
// now we have the mnes added to wallet | ||
const acc1 = harmony.wallet.addByMnemonic(mne, 0) | ||
|
||
// now we create contract using extracted abi | ||
// const myContract = harmony.contracts.createContract(abi) | ||
|
||
// first we get the account's balance to see if we have enough token on the testnet | ||
acc1.getBalance().then(res => { | ||
console.log(`-- hint: account balance of ${acc1.address}`) | ||
console.log(``) | ||
console.log({ account: res }) | ||
console.log(``) | ||
console.log(``) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="apple-mobile-web-app-capable" content="yes" /> | ||
<meta name="apple-mobile-web-app-status-bar-style" content="black" /> | ||
<meta name="format-detection" content="telephone=no" /> | ||
<meta name="format-detection" content="email=no" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" | ||
/> | ||
<title></title> | ||
</head> | ||
<style> | ||
#nodeUrl, | ||
#address { | ||
width: 250px; | ||
height: 50px; | ||
font-size: 16px; | ||
} | ||
|
||
#setProviderButton, | ||
#getBlanceButton { | ||
width: 100px; | ||
height: 50px; | ||
margin-left: 16px; | ||
background: rgba(0, 0, 0, 1); | ||
color: #ffffff; | ||
} | ||
</style> | ||
|
||
<body> | ||
<div id="root"> | ||
|
||
</div> | ||
|
||
<script src="../dist/HarmonyJs.browser.js"></script> | ||
<script> | ||
|
||
const harmony= new HarmonyJs.Harmony('ws://localhost:9128',0); | ||
|
||
// console.log() | ||
|
||
|
||
|
||
|
||
const biubiubiu = async () => { | ||
const p= await harmony.blockchain.newBlockHeaders() | ||
// harmony.blockchain.newBlockHeaders() | ||
|
||
|
||
p.onData(res=>{ | ||
console.log(res) | ||
}).on('error',error=>{ | ||
console.log(error) | ||
}) | ||
setTimeout(()=>{ | ||
if(p.subscriptions!=={}){ | ||
p.clearSubscriptions('eth_unsubscribe').then(res=>{ | ||
if(res){ | ||
console.log('Successfully unsubscribed!') | ||
} | ||
}) | ||
} | ||
},50000) | ||
|
||
} | ||
|
||
setTimeout(biubiubiu, 100); | ||
|
||
|
||
|
||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.