Coinmonks
Published in

Coinmonks

Smart Contracts on Ethereum

tl;dr & Show Me The Code!

Hello World API App

$ cargo new eth-demo-api
[dependencies]
tokio = { version = "1", features = ["full"] }
warp = "0.3"
web3 = "0.16.0"
hex = "0.4"
log = "0.4"
env_logger = "0.8"
dotenv = "0.15"

Whitelist Smart Contract

$ mkdir $HOME/eth-demo-vault
$ cd $HOME/eth-demo-vault
$ truffle init

MetaMask and Infura Project

Configure Truffle

MNEMONIC="<your metamask recovery phrase>"
INFURA_PROJECT="<your infura project key for kovan network>"
$ npm install -D @truffle/hdwallet-provider
$ npm install -D dotenv
0x9326BFA02ADD2366b30bacB125260Af641031331
AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331)
$ truffle compile
$ truffle migrate --network kovan
...2_deploy_contracts.js
=====================
Deploying 'DemoVault'
---------------------
> transaction hash: 0x262641...6ea4f12c
> Blocks: 1 Seconds: 16
> contract address: 0xfDf181...65fA1D2F
> block number: 25230313
> block timestamp: 1622686868
> account: 0xFCa4C8...9d3D565f
> balance: 2.0539430121993214
> gas used: 1064540 (0x103e5c)
> gas price: 20 gwei
> value sent: 0 ETH
> total cost: 0.0212908 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.0212908 ETH
Summary
=======
> Total deployments: 2
> Final cost: 0.02625488 ETH

Finish the Validator Struct

RUST_LOG=debug
MNEMONIC="<your metamask recovery phrase>"
INFURA_PROJECT="<your infura project key for kovan network>"
VAULT_ADDRESS="<contract address of your DemoVault contract>"
$ solc -o target --abi ../eth-demo-vault/contracts/*.sol
$ cargo run
No key for 127.0.0.1!

Interact with the Contract

$ truffle console --network kovan
let vault = await DemoVault.deployed();
let price = await vault.getPrice();
await vault.purchase(
"127.0.0.1",
{ from: accounts[1], value: price }
);
await vault.isValid("127.0.0.1");
Hello, world from 127.0.0.1!

Join Coinmonks Telegram Channel and learn about crypto trading and investing

Also, Read

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store