DumbContracts
所属分类:以太坊
开发工具:Solidity
文件大小:219KB
下载次数:0
上传日期:2023-01-20 16:27:08
上 传 者:
sh-1993
说明: 学习和玩以太坊智能合约
(Learning and playing with Ethereum Smart Contracts)
文件列表:
LICENSE (35149, 2023-01-21)
artifacts (0, 2023-01-21)
artifacts\CallMe.json (31733, 2023-01-21)
artifacts\CallMe_metadata.json (1904, 2023-01-21)
artifacts\HelloWorld.json (432698, 2023-01-21)
artifacts\HelloWorld_metadata.json (2843, 2023-01-21)
artifacts\MakeCall.json (125125, 2023-01-21)
artifacts\MakeCall_metadata.json (2830, 2023-01-21)
artifacts\test3.json (99813, 2023-01-21)
artifacts\test3_metadata.json (1070, 2023-01-21)
average.sol (1271, 2023-01-21)
calling.sol (568, 2023-01-21)
calling (0, 2023-01-21)
calling\contracts (0, 2023-01-21)
calling\contracts\calling.sol (821, 2023-01-21)
calling\contracts\makecall.sol (2140, 2023-01-21)
calling\migrations (0, 2023-01-21)
calling\migrations\1_deploy_contracts.js (192, 2023-01-21)
calling\test (0, 2023-01-21)
calling\truffle-config.js (4826, 2023-01-21)
contract1.sol (2575, 2023-01-21)
decompile (0, 2023-01-21)
decompile\contracts (0, 2023-01-21)
decompile\contracts\Inbox.sol (491, 2023-01-21)
decompile\contracts\Migrations.sol (518, 2023-01-21)
decompile\decompiled (0, 2023-01-21)
decompile\decompiled\bytecode (6485, 2023-01-21)
decompile\decompiled\v1.sol (2630, 2023-01-21)
decompile\decompiled\v2.sol (18160, 2023-01-21)
decompile\migrations (0, 2023-01-21)
decompile\migrations\1_initial_migration.js (125, 2023-01-21)
... ...
# DumbContracts
Learning and playing with Ethereum Smart Contracts
## Setup
Make sure to start `ganache` in a background terminal to act as our blockchain.
## Truffle
Make a directory for the code. The project will be a basic inbox.
```bash
mkdir inboxProject
cd inboxProject
truffle init
truffle create contract Inbox
truffle create test Inbox
```
Some notes say to use `truffle unbox` instead.
Compile a project:
```bash
truffle compile
```
Modify the `truffle-config.js` file to point at ganache.
```js
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`
```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:
```bash
truffle develop
```
Migrate / 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("***")
{
tx: '0x47d229d7b827f2d603a181b6b6***3dc7d008a53650835ab***5789466bee39fb0',
receipt: {
transactionHash: '0x47d229d7b827f2d603a181b6b6***3dc7d008a53650835ab***5789466bee39fb0',
transactionIndex: 0,
blockNumber: 2,
blockHash: '0xfb3c931d5a9733d954f22203178d4ac0***c79428a26abe0f5dec845d8767a6a4',
from: '0xc9cf9***33173a4741e706704679aa93e9c605a58',
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()
'***'
```
Trying to work out how to access a contract by address from inside truffle. Using require looks promising but can't make it work.
[https://ethereum.stackexchange.com/questions/45305/truffle-develop-get-new-contract-instance-from-contract-address]
[Some useful stuff here][developDeploy]
## Tools
* [Panoramix][panoramix]
* [dedaub][dedaub]
* [ethervm][ethervm]
* [Truffle Flattener][truffleflatten] - Squashes a Truffle project down into a single file to make debugging easier
* [vim-solidity][vimsolidity] - Vim Plugin
## Install
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
```
## Tutorials and useful stuff
* [REVERSE ENGINEERING A CONTRACT][rev1]
* [Debugging Contracts][debug1]
* [A good video on setting up VS Code][vscodelink]
* [Some example code][byexample]
* [Flash load code example][aaveflashloan]
Three ways to send cash, [this paper][transfer] talks about them and the security problems with them.
* [Calling other contracts][calling].
* [Video on using encoding methods][videoEncoding].
* [Video workshop on decompiling contracts][videoDecompileWorkshop].
[byexample]: https://solidity-by-example.org/sending-ether/
[vscodelink]: https://www.youtube.com/watch?v=tcnpGeOiA_
[transfer]: https://fravoll.github.io/solidity-patterns/secure_ether_transfer.html
[calling]: https://medium.com/@blockchain101/calling-the-function-of-another-contract-in-solidity-f9edfa921f4c
[videoEncoding]: https://www.youtube.com/watch?v=70_2YHJvKIc
[videoDecompileWorkshop]: https://archive.devcon.org/archive/watch/5/the-inner-workings-of-a-smart-contract-decompiler/?tab=YouTube
[panoramix]: https://github.com/palkeo/panoramix
[dedaub]: https://library.dedaub.com/decompile
[ethervm]: https://ethervm.io/decompile
[rev1]: https://ethereum.org/en/developers/tutorials/reverse-engineering-a-contract/
[developDeploy]: https://blog.logrocket.com/truffle-suite-tutorial-develop-ethereum-smart-contracts/
[vimsolidity]: https://github.com/tomlion/vim-solidity
[debug1]: https://medium.com/linum-labs/error-vm-exception-while-processing-transaction-revert-8cd856633793
[truffleflatten]: https://www.npmjs.com/package/truffle-flattener
[aaveflashloan]: https://www.quicknode.com/guides/defi/how-to-make-a-flash-loan-using-aave
近期下载者:
相关文件:
收藏者: