mkdir myproject
cd myproject
npm install -g truffle
truffle initStart the develop console:
truffle developRunning Unit Tests:
truffle testaccounts
It will use the default / first account when running a deployment.
compile
deployYou can get the account from the output of the deploy command.
To add a file reference interactively, get the instance at the deployed address:
let c = S3FileStorage.at("0x...") // or S3FileStorage.deployed()
c.addFileReference('<fileid>','https://<url>','<HASH>')To show that it doesn't work i.e. not the owner (assuming accounts[0] is the owner):
c.addFileReference('<fileid>','https://<url>','<HASH>', {from: accounts[3]})Should return an error.
-
Using a hosted blockchain node, sign up for keys at Infura.
-
Install an HD Wallet Provider which will manage private keys for us.
npm install @truffle/hdwallet-provider- Create a
.envfile and have the following values filled out:
MNEMONIC=""
INFURA_KEY=""
-
Go to https://www.rinkeby.io/#faucet and add ETH into one of your wallets. Use the reference link below to generate those keys.
-
Deploy to Rinkeby You can also append
--dry-runto make sure everything is ok. Sometimes wrong accounts are used or there isn't enough ETH in the account.
truffle deploy --network rinkebyYou should see something like this:
Migrations dry-run (simulation)
===============================
> Network name: 'rinkeby-fork'
> Network id: 4
> Block gas limit: 0x989680
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> block number: 5897700
> block timestamp: 1580605566
> account: 0x1EacB1739bE1A3aA8F115Ad2021D69a775df8698
> balance: 18.74970165
> gas used: 149175
> gas price: 2 gwei
> value sent: 0 ETH
> total cost: 0.00029835 ETH
-------------------------------------
> Total cost: 0.00029835 ETH
2_deploy_s3filestore.js
=======================
Deploying 'S3FileStorage'
-------------------------
> block number: 5897702
> block timestamp: 1580605579
> account: 0x1EacB1739bE1A3aA8F115Ad2021D69a775df8698
> balance: 18.74802706
> gas used: 809954
> gas price: 2 gwei
> value sent: 0 ETH
> total cost: 0.001619908 ETH
-------------------------------------
> Total cost: 0.001619908 ETH
Summary
=======
> Total deployments: 2
> Final cost: 0.001918258 ETH
Once deployed, grab the contract address and put it into the explorer: https://www.rinkeby.io/#explorer
Setup your environment with python 3.7
pipenv --python 3.7
pipenv installThis is a transaction and requires some gas. Open up createTransaction.py to have a look. It's setup to run locally but can be modified in the comments to point to a hosted node on Infura.
Have the following environment variables set:
CONTRACT_ADDRESS and PRIVATE_KEY
Run:
pipenv run python -m examples.createTransaction- Do Not whitelist the contract address. That will throw a 403 error.
- Using web3, we must build and send the raw transaction
For Infura, run:
pipenv run python -m examples.createTransactionInfura
Make sure you change the values to match in readContractData.py
pipenv run python -m examples.readContractDataIt should spit back the values you put on the blockchain earlier.