您现在的位置是:首页 >其他 >Solidity开发入门问题汇总网站首页其他

Solidity开发入门问题汇总

just-julie 2024-06-17 10:15:03
简介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. 联盟链新增节点

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。