java web3j4.8.4版本的使用记录

这篇具有很好参考价值的文章主要介绍了java web3j4.8.4版本的使用记录。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

最近公司做NFT市场开发,特记录一下自己在使用web3j组件测试调用区块链合约的时使用的方法和踩过的坑,便于自己以后查看。

主要用到工具有4个

idea,谷歌浏览,小狐狸钱包(metamask)插件,remix在线智能合约平台

1、准备工作

1.1、java项目

 在pom.xml中添加引用仓库地址,添加web3j的引入

    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>

    <dependencies>

        <!--web3j-->
        <dependency>
            <groupId>org.web3j</groupId>
            <artifactId>core</artifactId>
            <version>4.8.4</version>
            <exclusions>
                <exclusion>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-stdlib</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.squareup.okhttp3</groupId>
                    <artifactId>okhttp</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

1.2、智能合约

        开始前,必须有一个用于测试的区块链智能合约,进入以太坊官网提供的在线平台,地址为:https://remix.ethereum.org/,编写测试合约。

java web3j4.8.4版本的使用记录

        编写完成,编译测试无误后,部署合约,方法选择如下

java web3j4.8.4版本的使用记录

        因为选择通过web3的方式来发布合约,所以同步会要求登录小狐狸(MetaMask),我这里事先就已经添加好了币安测试链,如果各位没有添加的话,自己自行添加哈

java web3j4.8.4版本的使用记录

1.3 合约转化

         合约发布成功后,测试一下合约内的方法是否可以正常使用,一切OK了以后,在remix中的编译模块内,将abi和bin保存放入本地文件中用于生成java文件。

java web3j4.8.4版本的使用记录

java web3j4.8.4版本的使用记录

说明一下哦,在生成java文件时,本地要有web3j的资源文件,我事先已经做好了准备工作了,如果你们没有的话,就自己查下哈。

进入cmd命令窗口

java web3j4.8.4版本的使用记录

命令如下

web3j solidity generate --abiFile=abi文件地址 -o 文件生成地址 -p 文件包名

 java web3j4.8.4版本的使用记录

 以下是我的合约生成的java文件

package com.XX.XXX.contracts.constants;

import io.reactivex.Flowable;
import io.reactivex.functions.Function;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.web3j.abi.EventEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.Utf8String;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.RemoteFunctionCall;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.core.methods.response.BaseEventResponse;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
import org.web3j.tx.gas.ContractGasProvider;

/**
 * <p>Auto generated code.
 * <p><strong>Do not modify!</strong>
 * <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
 * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 
 * <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
 *
 * <p>Generated with web3j version 4.5.5.
 */
@SuppressWarnings("rawtypes")
public class EventTest extends Contract {
    private static final String BINARY = "Bin file was not provided";

    public static final String FUNC_CHANGENAME = "changeName";

    public static final String FUNC_COUNTS = "counts";

    public static final String FUNC_INCREMENT = "increment";

    public static final String FUNC_NAME = "name";

    public static final Event INCREMENT_EVENT = new Event("Increment", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>(true) {}, new TypeReference<Address>() {}));
    ;

    public static final Event CHANGENAMEEVENT_EVENT = new Event("changeNameEvent", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}, new TypeReference<Address>() {}));
    ;

    @Deprecated
    protected EventTest(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    protected EventTest(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
        super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
    }

    @Deprecated
    protected EventTest(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    protected EventTest(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
        super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
    }

    public List<IncrementEventResponse> getIncrementEvents(TransactionReceipt transactionReceipt) {
        List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(INCREMENT_EVENT, transactionReceipt);
        ArrayList<IncrementEventResponse> responses = new ArrayList<IncrementEventResponse>(valueList.size());
        for (Contract.EventValuesWithLog eventValues : valueList) {
            IncrementEventResponse typedResponse = new IncrementEventResponse();
            typedResponse.log = eventValues.getLog();
            typedResponse.which = (BigInteger) eventValues.getIndexedValues().get(0).getValue();
            typedResponse.who = (String) eventValues.getNonIndexedValues().get(0).getValue();
            responses.add(typedResponse);
        }
        return responses;
    }

    public Flowable<IncrementEventResponse> incrementEventFlowable(EthFilter filter) {
        return web3j.ethLogFlowable(filter).map(new Function<Log, IncrementEventResponse>() {
            @Override
            public IncrementEventResponse apply(Log log) {
                Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(INCREMENT_EVENT, log);
                IncrementEventResponse typedResponse = new IncrementEventResponse();
                typedResponse.log = log;
                typedResponse.which = (BigInteger) eventValues.getIndexedValues().get(0).getValue();
                typedResponse.who = (String) eventValues.getNonIndexedValues().get(0).getValue();
                return typedResponse;
            }
        });
    }

    public Flowable<IncrementEventResponse> incrementEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(INCREMENT_EVENT));
        return incrementEventFlowable(filter);
    }

    public List<ChangeNameEventEventResponse> getChangeNameEventEvents(TransactionReceipt transactionReceipt) {
        List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(CHANGENAMEEVENT_EVENT, transactionReceipt);
        ArrayList<ChangeNameEventEventResponse> responses = new ArrayList<ChangeNameEventEventResponse>(valueList.size());
        for (Contract.EventValuesWithLog eventValues : valueList) {
            ChangeNameEventEventResponse typedResponse = new ChangeNameEventEventResponse();
            typedResponse.log = eventValues.getLog();
            typedResponse.str = (String) eventValues.getNonIndexedValues().get(0).getValue();
            typedResponse.who = (String) eventValues.getNonIndexedValues().get(1).getValue();
            responses.add(typedResponse);
        }
        return responses;
    }

    public Flowable<ChangeNameEventEventResponse> changeNameEventEventFlowable(EthFilter filter) {
        return web3j.ethLogFlowable(filter).map(new Function<Log, ChangeNameEventEventResponse>() {
            @Override
            public ChangeNameEventEventResponse apply(Log log) {
                Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(CHANGENAMEEVENT_EVENT, log);
                ChangeNameEventEventResponse typedResponse = new ChangeNameEventEventResponse();
                typedResponse.log = log;
                typedResponse.str = (String) eventValues.getNonIndexedValues().get(0).getValue();
                typedResponse.who = (String) eventValues.getNonIndexedValues().get(1).getValue();
                return typedResponse;
            }
        });
    }

    public Flowable<ChangeNameEventEventResponse> changeNameEventEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(CHANGENAMEEVENT_EVENT));
        return changeNameEventEventFlowable(filter);
    }

    public RemoteFunctionCall<TransactionReceipt> changeName(String str) {
        final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
                FUNC_CHANGENAME, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(str)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteFunctionCall<TransactionReceipt> counts(BigInteger param0) {
        final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
                FUNC_COUNTS, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(param0)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteFunctionCall<TransactionReceipt> increment(BigInteger which) {
        final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
                FUNC_INCREMENT, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(which)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteFunctionCall<TransactionReceipt> name() {
        final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
                FUNC_NAME, 
                Arrays.<Type>asList(), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    @Deprecated
    public static EventTest load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return new EventTest(contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    @Deprecated
    public static EventTest load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return new EventTest(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    public static EventTest load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
        return new EventTest(contractAddress, web3j, credentials, contractGasProvider);
    }

    public static EventTest load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
        return new EventTest(contractAddress, web3j, transactionManager, contractGasProvider);
    }

    public static class IncrementEventResponse extends BaseEventResponse {
        public BigInteger which;

        public String who;
    }

    public static class ChangeNameEventEventResponse extends BaseEventResponse {
        public String str;

        public String who;
    }
}

 2、测试合约方法的调用和合约事件监听

   说明:

        web3j通过rpc的方式建立连接,连接方式我测试时,用了两种方式,一种是http的方式调用合约的方法,websocket的方式调用的事件监听,两种方式测试都是OK的

package com.xx.xxx.contracts.util;

import com.nft.service.contracts.constants.ContractConstants;
import com.nft.service.contracts.constants.EventTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.web3j.abi.EventValues;
import org.web3j.abi.datatypes.Type;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.RemoteFunctionCall;
import org.web3j.protocol.core.methods.request.Transaction;
import org.web3j.protocol.core.methods.response.EthEstimateGas;
import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.http.HttpService;
import org.web3j.protocol.websocket.WebSocketService;
import org.web3j.tx.Contract;
import org.web3j.tx.ReadonlyTransactionManager;
import org.web3j.tx.TransactionManager;
import org.web3j.tx.gas.DefaultGasProvider;

import java.io.IOException;
import java.math.BigInteger;
import java.net.ConnectException;
import java.util.concurrent.ExecutionException;

/**
 * @author viowio
 * @version v1.0
 * @date 17:52 2022/4/9
 * @description ERC20工具类
 */
public class TestUtil {


    private static Web3j web3j = Web3j.build(new HttpService("https://data-seed-prebsc-2-s1.binance.org:8545/"));
    private static final Logger logger = LoggerFactory.getLogger(TestUtil.class);

    public static void changeName(){
        String token = "合约地址";
        try {
            Credentials credentials = Credentials.create("换成自己的测试钱包地址私钥");
            BigInteger currentGasPrice = web3j.ethGasPrice().sendAsync().get().getGasPrice();
            EventTest eventTest = EventTest.load(token, web3j, credentials, new DefaultGasProvider() {
                /**
                 * 使用动态获取的 Gas Price
                 * @return
                 */
                @Override
                public BigInteger getGasPrice() {
                    return currentGasPrice;
                }
            });
            
            RemoteFunctionCall<TransactionReceipt> changeNames = eventTest.changeName("0x7503D2667a3Af2a5f5268B9628F7Bb0A3E6282B4");
            TransactionReceipt transactionReceipt = changeNames.sendAsync().get();
            String transactionHash = transactionReceipt.getTransactionHash();
            logger.info("changeName hash: {}",transactionHash);
        }catch (ExecutionException | InterruptedException ex){
            logger.info(ex.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void changeNameEvent() throws ConnectException {
        String token = "合约地址";
        String wsurl = ContractConstants.WEBSOCKET_RPC;
        //实例化websocket
        WebSocketService webSocketService = new WebSocketService(wsurl,true);
        //建立连接
        webSocketService.connect();
        //实例化web3j
        Web3j client = Web3j.build(webSocketService);
        TransactionManager transactionManager = new ReadonlyTransactionManager(web3j, token);
        try {
            //方式一
            /* client.ethLogFlowable(
                    new EthFilter(
                            DefaultBlockParameterName.EARLIEST,
                            DefaultBlockParameterName.LATEST,
                            // 合约地址
                            token
                    )
            ).subscribe(event -> {
                System.out.println(event);
                // => Log{removed=false, logIndex='0x39', transactionIndex='0x13', transactionHash='0x9c3653c27946cb39c3a256229634cfedbca54f146a740f46b661b986590f8358', blockHash='0x1e674b9d111601519f977b75f9a1865ba359b474550ff5d0d87daec1f543d64d', blockNumber='0xb83ccd', address='0x7b52aae43e962ce6a9a1b7e79f549582ae8bcff9', data='0x', type='null', topics=[0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, 0x0000000000000000000000000000000000000000000000000000000000000000, 0x0000000000000000000000006ab3d0bd875f8667026d2a9bb3060ec44380bcc2, 0x0000000000000000000000000000000000000000000000000000000000000017]}
            }, Throwable::printStackTrace);*/

            //方式二
            /*Credentials credentials = Credentials.create("换成自己的测试钱包地址私钥");
            BigInteger currentGasPrice = web3j.ethGasPrice().sendAsync().get().getGasPrice();
            EventTest eventTest = EventTest.load(token, web3j, credentials, new DefaultGasProvider() {
                *//**
                 * 使用动态获取的 Gas Price
                 * @return
                 *//*
                @Override
                public BigInteger getGasPrice() {
                    return currentGasPrice;
                }
            });
            eventTest
                    .changeNameEventEventFlowable(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST)
                    .subscribe(event -> {
                        Log log = event.log;
                        EventValues eventValues = Contract.staticExtractEventParameters(EventTest.CHANGENAMEEVENT_EVENT, log);
                        for (Type nonIndexedValue : eventValues.getNonIndexedValues()) {
                            System.out.println(nonIndexedValue.getValue());
                        }
                    });*/
            //方式3
            Credentials credentials = Credentials.create("换成自己的测试钱包地址私钥");
            BigInteger currentGasPrice = client.ethGasPrice().sendAsync().get().getGasPrice();
            EventTest eventTest = EventTest.load(token, client, credentials, new DefaultGasProvider() {
                /**
                 * 使用动态获取的 Gas Price
                 * @return
                 */
                @Override
                public BigInteger getGasPrice() {
                    return currentGasPrice;
                }
            });
            eventTest
                    .changeNameEventEventFlowable(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST)
                    .subscribe(event -> {
                        Log log = event.log;
                        logger.info("transactionHash: {}",log.getTransactionHash());
                        //解析时间返回的参数
                        EventValues eventValues = Contract.staticExtractEventParameters(EventTest.CHANGENAMEEVENT_EVENT, log);
                        for (Type nonIndexedValue : eventValues.getNonIndexedValues()) {
                            System.out.println(nonIndexedValue.getValue());
                        }
                    });
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}

事件测试结果

16:32:05.978 [restartedMain] INFO  c.n.s.c.u.TestUtil - [lambda$changeNameEvent$0,146] - transactionHash: 0xd4fac21ba08d7496d8025281c37e932b914ea3bb9dce48e73bd3c08ac934fdd3
test
0x5ae241178c67689ead468bf5170b3105011a5766
16:32:05.979 [restartedMain] INFO  c.n.s.c.u.TestUtil - [lambda$changeNameEvent$0,146] - transactionHash: 0x42aff4ead062feb340a2fa68c73b5024a0d58029287a2f0acc62156c60780d97
test
0x5ae241178c67689ead468bf5170b3105011a5766
16:32:05.980 [restartedMain] INFO  c.n.s.c.u.TestUtil - [lambda$changeNameEvent$0,146] - transactionHash: 0x1050583b9e907378fb61289ab5b373f195f4d332c5fd7d273e2c817554c90f7b
123
0x5ae241178c67689ead468bf5170b3105011a5766
16:32:05.980 [restartedMain] INFO  c.n.s.c.u.TestUtil - [lambda$changeNameEvent$0,146] - transactionHash: 0xc86374d895f83bfef380a9a1f4cc5a15ddfcc78090305cff5e4367460d423af4
1237
0x5ae241178c67689ead468bf5170b3105011a5766
16:32:05.981 [restartedMain] INFO  c.n.s.c.u.TestUtil - [lambda$changeNameEvent$0,146] - transactionHash: 0xf76fbd23e603109752215c5455e3920a08583de8728c2a42699f61aa45959d29
12374
0x5ae241178c67689ead468bf5170b3105011a5766
16:32:05.981 [restartedMain] INFO  c.n.s.c.u.TestUtil - [lambda$changeNameEvent$0,146] - transactionHash: 0x0d751916f7ae66162959138c0a700feb136153fabee8d8b25a10e410fe74f904
1237455
0x5ae241178c67689ead468bf5170b3105011a5766
16:32:05.981 [restartedMain] INFO  c.n.s.c.u.TestUtil - [lambda$changeNameEvent$0,146] - transactionHash: 0xe03249489b93e287e9d033f547c2a36a741c7b3ae49e5c95542315816f4af572
12374556
0x5ae241178c67689ead468bf5170b3105011a5766

OK,暂时完事了。

最后补充一下

如果没有的rpc地址的,可以搜一下,也可以使用我上面的那个地址,不过仅限于测试用哦。文章来源地址https://www.toymoban.com/news/detail-412833.html

到了这里,关于java web3j4.8.4版本的使用记录的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【web3j】java通过web3j监听并解析合约中的事件(event/emit)

    ① 查询链上数据用的rpc(本示例是binance的,测试网可以使用:https://data-seed-prebsc-2-s2.binance.org:8545) ② 自己还要有一个测试链上部署好的合约,合约中要有一个方法emit了事件。 ③ java依赖 一、 通过自己合约的abi和bin生成一个java文件,abi和bin可以在remix的compiler模块中获取,

    2024年02月09日
    浏览(25)
  • java使用web3j,部署智能合约在测试链上,并调用(万字详细教程)

    最近在学区块链相关,想做点自己感兴趣的。网上关于这块部分的坑也比较多,最近也是问了很多行业从事者才慢慢填坑,因此记录下来分享一下。 钱包 :metemask、 solidity编译器 :remix 、 java ide :idea。 智能合约编写的我选择在remix上方便,而且部署的时候不需要自定义gasP

    2024年01月16日
    浏览(28)
  • Java Web3j nonce 获取

    Web3j 获取 nonce 的参考代码 获取一个 address nonce 值的时候,其中有一个参数为 DefaultBlockParameter,上面代码中采用的是 DefaultBlockParameterName 类,它有 3 个值,分别为 EARLIEST ( \\\"earliest\\\" ) LATEST ( \\\"latest\\\" ) PENDING ( \\\"pending\\\" ) earliest:创世区块 latest:最新区块 (区块链的头号区块) pending:

    2024年02月14日
    浏览(39)
  • Web3j使用教程(2)

    首先安装solc(用于编译智能合约)和web3j命令行工具(用于打包智能合约) npm install -g solc web3j安装地址: Releases · web3j/web3j · GitHub,选择对应操作系统 首先准备一个智能合约 Owner.sol,建议先在remix上测试一下Remix - Ethereum IDE 先编译  solcjs Owner.sol --bin --abi --optimize -o . 然后

    2023年04月24日
    浏览(32)
  • java通过web3j获取ETH交易明细

        我们在项目里面如果想要得到用户的ETH交易明细怎么做呢?有两种方式:    1、直接获取ETH最新块的交易明细。    2、通过块获取用户的交易明细。 废话不多说,直接贴代码看了          下面是项目的相关依赖:

    2024年02月05日
    浏览(26)
  • Java与智能合约交互(Web3j)- write函数

    说在前头 Web3是一种新兴的网络概念,由于某些原因导致我们能够接触到的相关技术知识实在有限,每当我遇见技术瓶颈总是不能找到充足的资料,这也让我萌生了填补这片空白知识的冲动。 “Hello Web3” 这个专栏会尽力将我掌握的web3 知识分享给大家。如果分享的知识能帮助

    2023年04月08日
    浏览(26)
  • 【WEB3】如何使用Web3J库开发应用连接到以太坊区块链网络

    ​ Web3j 是一个与以太坊智能合约交互并与以太坊节点集成的 Java 库。它是高度模块化、类型安全和反应式的,专为以太坊上的 Java 和 Android 开发而构建。Web3j 消除了编写自定义集成代码以连接到以太坊区块链网络的开销。 通过 HTTP 和 IPC 实现完整的 Ethereum JSON-RPC客户端 API,

    2024年02月02日
    浏览(32)
  • web3j的基础用法-3ETH交易监听器

    demo简单实现了4种 监听区块 监听所有交易 监听待上链的交易 监听指定合约的交易事件(例如监控大户流转,实现跟单,抛售等后续逻辑) github 地址 https://github.com/jambestwick/we3jdemo

    2024年02月11日
    浏览(29)
  • web3j 引用报错:okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)解决

    在做区块链开发时引用了web3j,而web3j中又引用了OKhttp,在程序发起请求时报错如下 我项目中引用的web3j包如下 其实具体web3j哪个版本感觉都有类似问题,我尝试过4.6.3版本到5.0.0都会报上述错。然后看项目依赖发现引用的OKhttp版本是3.14.9,网上说要将OKhttp版本号更换到4.3.1以上

    2024年02月09日
    浏览(17)
  • Web3j 继承StaticStruct的类所有属性必须为Public <DynamicArray<StaticStruct>>

    Web3j 继承StaticStruct的类所有属性必须为Public,属性的顺序和数量必须和solidity 里面的struct 属性相同,否则属性少了或者多了的时候会出现错位 Web3j 继承StaticStruct的类所有属性不能为private,因为web3j 是通过长度去截取返回值解析成对应的属性进行赋值的。要获取一个list对象时

    2024年02月09日
    浏览(20)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包