Skip to content
Permalink
Browse files

Add .env files

  • Loading branch information
ilanolkies committed Mar 23, 2020
1 parent d95f73c commit 844c01f713bec168daa1e9fc915917fed9a03e6d
Showing with 5,456 additions and 233 deletions.
  1. +1 −0 .gitignore
  2. +42 −0 REDME.md
  3. +3 −0 dapp/.env
  4. +3 −0 dapp/.env.production
  5. +10 −6 dapp/src/App.js
  6. +5,382 −133 package-lock.json
  7. +1 −0 package.json
  8. +14 −94 truffle-config.js
@@ -1,2 +1,3 @@
node_modules/
build/
.secret
@@ -1 +1,43 @@
# Hello world RSK

Hello World decentralized application in RSK network.

## Run locally

In one terminal:

```
npm i
npx truffle develop
truffle(develop)> migrate
```

In another terminal:

```
cd dapp
yarn
yarn start
```

## Run on testnet

```
cd dapp
yarn
yarn build
```

Serve it with

```
yarn global add serve
serve -s build
```

## Source

- `contracts/`: smart contracts for the dapp
- `test/` : unit tests for smart contracts
- `migrations/`: smart contract deployment scripts
- `dapp/`: react app to operate with smart contracts
@@ -0,0 +1,3 @@
REACT_APP_NODE_ENDPOINT=http://localhost:9545
REACT_APP_NET_ID=5777
REACT_APP_HELLO_WORLD_ADDRESS=0x138a4c489A657BA9419f21C2E0c4d9B265a67341
@@ -0,0 +1,3 @@
REACT_APP_NODE_ENDPOINT=https://public-node.testnet.rsk.co
REACT_APP_NET_ID=31
REACT_APP_HELLO_WORLD_ADDRESS=0xe1db8d54450c45e63f0e60a699cab992aaf8fac2
@@ -26,7 +26,7 @@ class App extends Component {
getMessage() {
this.setState({ message: null });

const web3 = new Web3('http://localhost:9545');
const web3 = new Web3(process.env.REACT_APP_NODE_ENDPOINT);

const helloWorld = new web3.eth.Contract([
{
@@ -40,7 +40,7 @@ class App extends Component {
stateMutability: "view",
type: "function",
},
], '0x138a4c489A657BA9419f21C2E0c4d9B265a67341');
], process.env.REACT_APP_HELLO_WORLD_ADDRESS);

helloWorld.methods.getMessage().call().then(message => this.setState({ message }));
}
@@ -63,7 +63,7 @@ class App extends Component {

web3.eth.net.getId()
.then(networkId => {
if (networkId !== 5777) this.setState({ error: 'Wrong network. Please connect to your local network.' });
if (networkId.toString() !== process.env.REACT_APP_NET_ID) this.setState({ error: 'Wrong network. Please connect to your local network.' });
else {
const helloWorld = new web3.eth.Contract([
{
@@ -77,14 +77,17 @@ class App extends Component {
stateMutability: "nonpayable",
type: "function",
},
], '0x138a4c489A657BA9419f21C2E0c4d9B265a67341');
], process.env.REACT_APP_HELLO_WORLD_ADDRESS);

return helloWorld.methods.setMessage(newMessage).send({ from: accounts[0] })
.on('receipt', ({ transactionHash }) => this.setState({ transactionHash }))
.on('receipt', ({ transactionHash }) => {
this.setState({ transactionHash, setting: false });
return this.getMessage();
})
.catch(error => this.setState({ error: error.message, setting: false }))
}
});
}).catch(error => this.setState({ error: error.message, setting: false }))
.finally(() => this.getMessage());
}

render() {
@@ -112,6 +115,7 @@ class App extends Component {
<Button onClick={this.setMessage} disabled={setting}>Set Message</Button>
</InputGroup>
</Row>
{setting && <Row><Col><Spinner animation="border" /></Col></Row>}
{error && <Row><Col><Alert variant="danger">{error}</Alert></Col></Row>}
{transactionHash && <Row><Col><Alert variant="success">Success! Transaction id: {transactionHash}</Alert></Col></Row>}
</>

0 comments on commit 844c01f

Please sign in to comment.
You can’t perform that action at this time.