Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasabi.js cleaned scope, and removed inject contracts as global variables. #9

Merged
merged 5 commits into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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;
}
});
})();