Solidity开发入门问题汇总

  1. 开发环境搭建
    http://www.17bigdata.com/study/programming/solidity/solidity-setup.html

  2. Source file requires different compiler version (current compiler is 0.8.19+commit.7dd6d404.Emscripten.clang)

     将文件solidity ^0.7.0 修改为solidity ^0.8.14
    
  3. ide 工具安装

pip3 install sphinx sphinx_rtd_theme
pip3 install myst-parser
git clone https://github.com/ethereum/remix-ide.git
cd docs/
make html
  1. 搭建私链节点

     http://club.coder55.com/article?id=86681
    

自定义一个创世区块的json配置文件genesis.json,与保存数据目录data

 geth --datadir /Users/liangw/Desktop/data/geth/local_ethereum_blockchain init local_ethereum_blockchain/genesis.json

启动geth

 geth --datadir data0  --networkid 8888 --port 30303 --http --http.addr "0.0.0.0" --http.port 8545 --http.api 'db,net,eth,web3,personal' --nodiscover --allow-insecure-unlock --http.corsdomain '*' console 2>> geth.log

Failed to write genesis block: unsupported fork ordering: eip150Block not enabled, but eip155Block enabled at block 0

{
  "config": {
    "chainId": 666,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "ethash": {}
  },
  "nonce": "0x0",
  "timestamp": "0x5ddf8f3e",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x47b760",
  "difficulty": "0x00002",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": { },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
 

personal is not defined

  mac 安装 geth version 1.11.6-stable-ea9e62ca出现的问题,将安装包换成1.10.26-stable
  下载链接https://geth.ethereum.org/downloads
 https://zhuanlan.zhihu.com/p/515941029?utm_id=0
  1. 以太坊钱包连接本地私有链

       1. chrome浏览器下载MetaMask插件
       2. 添加本地区块网络
       3. 注意:有可能因为区块启动的时候没有配置crossOrigin 导致连接不上问题,可以用上面的区块启动命令解决。
    
  2. metamask 显示测试网络

    https://zhuanlan.zhihu.com/p/449202045
    
  3. 使用truffle 构建智能合约 部署以及测试

     https://blog.csdn.net/ling1998/article/details/124146467
    

    truffle console报错在这里插入图片描述
    修改为 truffle console --network develop
    在这里插入图片描述

  4. java调用智能合约

     https://blog.csdn.net/qq_43707926/article/details/123855626
    

    报“only replay-protected (EIP-155) transactions allowed over RPC”是因为什么

      启动指令添加 --rpc.allow-unprotected-txs
    

调用代码:


import org.web3j.abi.datatypes.Utf8String;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.WalletUtils;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.http.HttpService;

import java.math.BigInteger;
import java.util.List;

public class Testcontract {


    public static void main(String[] arg) throws Exception {

        Web3j web3j = Web3j.build(new HttpService("http://127.0.0.1:8545"));
        BigInteger gasPrices = web3j.ethGasPrice().send().getGasPrice();
        System.out.println(gasPrices);

        BigInteger gasLimit = new BigInteger("1000000");

        // 设置钱包账户
        Credentials credentials = WalletUtils.loadCredentials("123456", "/Users/liangw/Desktop/data/geth/privatekey/account3.json");
        System.out.println(credentials.getAddress());
        Utf8String utf8String = new Utf8String("你好啊");
        // 部署合约,这里Test_sol_testEth是由web3j生成的java文件的类,需要改成你自己的类名
        Hello_sol_Hello deployContract = Hello_sol_Hello.deploy(web3j, credentials, gasPrices, gasLimit, utf8String).send();

        // 部署完成后打印合约地址
        System.out.println(deployContract.getContractAddress());

        // 判断部署的合约是否可用
        System.out.println(deployContract.isValid());


        // 调用合约
        Hello_sol_Hello testContract = new Hello_sol_Hello(deployContract.getContractAddress(), web3j,
                credentials, gasPrices, gasLimit);
        Utf8String send = testContract.getValue().send();
        System.out.println("-----*****-------");
        System.out.println("******----******" + send);
    }
}

  1. 单机搭建联盟链

      https://blog.csdn.net/weixin_47174945/article/details/125391880
    

    如何将 openSSL Version 由LibreSSL 2.8.3修改为OpenSSL 3.1.0 14

     https://qa.1r1g.com/sf/ask/4353712891/ 
    

    延伸阅读

     	https://zhuanlan.zhihu.com/p/492913063 	
    
  2. 联盟链新增节点

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值