mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-27 05:56:21 +00:00
ad30a98169
Upgrade all dependencies on web3/web3-* v1.0.0-beta.37 to v1.2.1. Make various adjustments related to the previous convention of `"web3": "1.0.0-beta"` in `embark.json` signifying that embark's own web3 dependency should be used in dapp builds. Fix bugs in library manager, including a switch from using the live-plugin-manager package to using npm in a child process to install `"versions"` dependencies specified in `embark.json` when a specified version doesn't match up with embark's own version for that package. Avoid race conditions when installing `"versions"` by completing all installs prior to starting other services. If an install fails, then after all the installs have completed or failed the embark command will exit with error. Change various comments and update docs to reflect the new default of web3 v1.2.1.
40 lines
978 B
Markdown
40 lines
978 B
Markdown
title: Smart Contract Objects
|
|
layout: docs
|
|
---
|
|
### Interacting with contracts in Javascript
|
|
|
|
Embark will automatically take care of deployment for you and set all needed JS bindings. For example, the contract below:
|
|
|
|
```
|
|
// app/contracts/simple_storage.sol
|
|
|
|
contract SimpleStorage {
|
|
uint public storedData;
|
|
|
|
function SimpleStorage(uint initialValue) {
|
|
storedData = initialValue;
|
|
}
|
|
|
|
function set(uint x) {
|
|
storedData = x;
|
|
}
|
|
function get() constant returns (uint retVal) {
|
|
return storedData;
|
|
}
|
|
}
|
|
```
|
|
|
|
Will automatically be available in Javascript as:
|
|
|
|
```
|
|
// app/js/index.js
|
|
|
|
import SimpleStorage from 'Embark/contracts/SimpleStorage';
|
|
|
|
SimpleStorage.methods.set(100).send();
|
|
SimpleStorage.methods.get().call().then(function(value) { console.log(value) });
|
|
SimpleStorage.methods.storedData().call().then(function(value) { console.log(value) });
|
|
```
|
|
|
|
The syntax used is <a href="https://web3js.readthedocs.io/en/v1.2.1/" target="_blank">web3.js 1.2.1</a>
|