Learning and playing with Ethereum Smart Contracts
Make sure to start ganache in a background terminal to act as our blockchain.
Make a directory for the code. The project will be a basic inbox.
mkdir inboxProject
cd inboxProject
truffle init
truffle create contract Inbox
truffle create test InboxSome notes say to use truffle unbox instead.
Compile a project:
truffle compileModify the truffle-config.js file to point at ganache.
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
}Check the migrations file migrations/1_deploy.js
const Inbox = artifacts.require("Inbox");
module.exports = function(deployer) {
// The contract name followed by parameters to the constructor.
deployer.deploy(Inbox, "Message 1");
};To get into the truffle console:
truffle developMigrate / deploy the contract then do stuff with it:
truffle(develop)> migrate
...
Summary
=======
> Total deployments: 1
> Final cost: 0.001666143 ETH
truffle(develop)> let instance = await Inbox.deployed()
undefined
truffle(develop)> let inbox = instance.getMessage()
undefined
truffle(develop)> instance.setMessage("aaa")
{
tx: '0x47d229d7b827f2d603a181b6b6983dc7d008a53650835ab985789466bee39fb0',
receipt: {
transactionHash: '0x47d229d7b827f2d603a181b6b6983dc7d008a53650835ab985789466bee39fb0',
transactionIndex: 0,
blockNumber: 2,
blockHash: '0xfb3c931d5a9733d954f22203178d4ac064c79428a26abe0f5dec845d8767a6a4',
from: '0xc9cf96433173a4741e706704679aa93e9c605a58',
to: '0xc1462c4a0efea0c29468729dd00c903018ebb3da',
cumulativeGasUsed: 28050,
gasUsed: 28050,
contractAddress: null,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00',
status: true,
effectiveGasPrice: 3281690333,
type: '0x2',
rawLogs: []
},
logs: []
}
truffle(develop)> instance.getMessage()
'aaa'
Trying to work out how to access a contract by address from inside truffle. Using require looks promising but can't make it work.
- Panoramix
- dedaub
- ethervm
- Truffle Flattener - Squashes a Truffle project down into a single file to make debugging easier
- vim-solidity - Vim Plugin
Install latest version of NodeJS:
curl -sL https://deb.nodesource.com/setup_19.x -o /tmp/nodesource_setup.sh
sudo bash /tmp/nodesource_setup.sh
Now install Ganache and Truffle
sudo npm install -g ganache truffle
- REVERSE ENGINEERING A CONTRACT
- Debugging Contracts
- A good video on setting up VS Code
- Some example code
- Flash load code example
Three ways to send cash, this paper talks about them and the security problems with them.