Skip to content

Commit

Permalink
Merge pull request #9 from hexeight/dev
Browse files Browse the repository at this point in the history
Wasabi.js cleaned scope, and removed inject contracts as global variables.
  • Loading branch information
omkarkhair committed Jul 17, 2017
2 parents f5438c4 + dbe9752 commit 3c7dbe1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 40 deletions.
13 changes: 8 additions & 5 deletions README.md
Expand Up @@ -19,23 +19,23 @@ wasabi init
## Configure
Wasabi can be configured to use an account on the RPC OR provide a `private_key` to sign contract deployment transactions locally. Local signing is helpful when using Infura or other public RPC nodes. If a `private_key` is provided, the `from` address will be ignored, and wasabi will perform client side signing for deployment transactions.

```
```js
{
// http endpoint for JSON RPC e.g. http://localhost:8545
"host": "http://localhost:8545",
"host": "http://localhost:8545",
// Maximum gas budget for a contract
"max_gas": "100000000",
// Deploy contract from address
"from": "0x00000000000000000000",
// Use private key to sign transactions in wasabi
//"private_key": "YOUR_PRIVATE_KEY",
//"private_key": "YOUR_PRIVATE_KEY",
// Path to contract files
"contracts": ["contracts/SimpleStorage.sol"]
"contracts": ["contracts/SimpleStorage.sol"]
}
```

## Compile
Complile solidity contracts listed in config and compile check for errors.
Complile solidity contracts listed in config and compile check for errors. Wasabi uses 'solc' for copiling solidity contracts.
```
wasabi compile
```
Expand All @@ -46,6 +46,9 @@ Deploy solidity contracts through the RPC node provided in config.
wasabi deploy
```

### Developing Dapps
On successful `wasabi deploy`, the contract address and ABI are made available in `app/contracts.json`. A scaffolded JS in also available in `app/wasabi.js`, which can be used in Dapps to populate `web3` contracts instances using `contracts.json`.

## Demo
Run a http server running at `http://localhost:8888` hosting static files in the `app` directory to test your Dapp.
```
Expand Down
73 changes: 38 additions & 35 deletions static/wasabi.js
@@ -1,38 +1,41 @@
function startApp () {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
var wasabi = JSON.parse(xmlHttp.responseText);
wasabi.forEach(function (contract, index) {
var definition = web3.eth.contract(contract.abi);
var c = definition.at(contract.address);
window[contract.name] = {
deployed: function () {
return c;
},
at: function (address) {
return definition.at(address);
}
};
});
(function () {
Wasabi = {};
function initWasabi () {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
var config = JSON.parse(xmlHttp.responseText);
config.forEach(function (contract, index) {
var definition = web3.eth.contract(contract.abi);
var c = definition.at(contract.address);
Wasabi[contract.name] = {
deployed: function () {
return c;
},
at: function (address) {
return definition.at(address);
}
};
});
}
}
xmlHttp.open("GET", "/contracts.json", true);
xmlHttp.send(null);
}
xmlHttp.open("GET", "/contracts.json", true);
xmlHttp.send(null);
}

window.addEventListener('load', function() {
window.addEventListener('web3-loaded', startApp());
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
window.web3 = new Web3(web3.currentProvider);
var event = new Event('web3-loaded');
window.dispatchEvent(event);
} else {
console.error("Web3 is undefined: Your browser does not support dApps. Please use Mist, Metamask of comparable dApp explorer.");
var event = new Event('web3-failed');
window.dispatchEvent(event);
return;
}
});
window.addEventListener('load', function() {
window.addEventListener('web3-loaded', initWasabi());
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
window.web3 = new Web3(web3.currentProvider);
var event = new Event('web3-loaded');
window.dispatchEvent(event);
} else {
console.error("Web3 is undefined: Your browser does not support dApps. Please use Mist, Metamask of comparable dApp explorer.");
var event = new Event('web3-failed');
window.dispatchEvent(event);
return;
}
});
})();

0 comments on commit 3c7dbe1

Please sign in to comment.