- 重新在Remix上测试合约成功后,将dapp目录下的contracts下对应的sol文件替换(以webpack生成的包为例子);
- 一般我会选择删除测试私链的数据,然后重新初始化、启动geth、新建账户、挖矿等;
rm -rf data/* nohup.out output.log geth --datadir data/ init genesis.json nohup geth --datadir data/ --networkid 15 --rpc --rpcapi db,eth,net,web3,personal,miner --rpcport 8545 --rpcaddr 0.0.0.0 --allow-insecure-unlock --nodiscover --rpccorsdomain "*" 2>output.log &
贴上相关的配置文件:
genesis.json{ "config": { "chainId": 15, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 0, "constantinopleBlock": 0, "petersburgBlock": 0, "istanbulBlock": 0 }, "alloc": {}, "coinbase": "0x0000000000000000000000000000000000000000", "difficulty": "0x100", "extraData": "", "gasLimit": "0xffffffff", "nonce": "0x0000000000000042", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "timestamp": "0x00" }
truffle-config.json
require('babel-register') module.exports = { networks: { development: { port: 8545, host: 'localhost', network_id: '*', gas: 6700000 } }, compilers: { solc: { version: "0.6.4" } } }
2_deploy_contracts.js
const SiLuan = artifacts.require("SiLuan"); module.exports = function(deployer) { deployer.deploy(SiLuan); };
-
生成合约的java文件以便导入idea
../relatedEnv/web3j-4.5.5/bin/web3j truffle generate build/contracts/SiLuan.json -o . -p .
前面这个是web3j的包的位置 -o 输出路径 -p 输出包
-
truffle migrate 部署合约
-
将合约地址、私钥、账户地址等参数导入项目
web3j: client-address: http://192.168.123.76:8545 password=123456 path=E:\\winshare\\UTC--2020-04-17T07-11-08.390910900Z--0e10b3a6c88909925401e7aa64efddf44670caa5 contract_address=0x36Bd220e5c71bBdf9c1aF0B64bC9918b7014ac7f user1_address=0x0e10b3a6c88909925401e7aa64efddf44670caa5 abi=[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"string",等等}]
-
input data的解析
导入包:
相关帮助:GitHub - prettymuchbryce/abidecoder: Kotlin and Java library for decoding data params and events from ethereum transactions<dependency> <groupId>org.ethereum</groupId> <artifactId>ethereumj-core</artifactId> <version>1.7.2-RELEASE</version> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-reflect</artifactId> <version>1.3.71</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib</artifactId> <version>1.3.71</version> </dependency> <dependency> <groupId>com.github.prettymuchbryce</groupId> <artifactId>abidecoder</artifactId> <version>3ae24ecb55</version> </dependency>
最后一个包需要基于前三个包,前三个包可以直接下,最后一个包需要添加repository后再下:
<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories> <dependency> <groupId>org.github.prettymuchbryce</groupId> <artifactId>abidecoder</artifactId> <version>master-SNAPSHOT</version> </dependency>
使用方法 import com.prettymuchbryce.abidecoder.Decoder; public class Main { public static void main(String[] args) { Decoder d = new Decoder(); d.addAbi(myAbiJsonString); Decoder.DecodedMethod result = d.decodeMethod(methodData); System.out.print(result); } }