国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

java web3j4.8.4版本的使用記錄

這篇具有很好參考價(jià)值的文章主要介紹了java web3j4.8.4版本的使用記錄。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

最近公司做NFT市場(chǎng)開發(fā),特記錄一下自己在使用web3j組件測(cè)試調(diào)用區(qū)塊鏈合約的時(shí)使用的方法和踩過的坑,便于自己以后查看。

主要用到工具有4個(gè)

idea,谷歌瀏覽,小狐貍錢包(metamask)插件,remix在線智能合約平臺(tái)

1、準(zhǔn)備工作

1.1、java項(xiàng)目

?在pom.xml中添加引用倉(cāng)庫地址,添加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、智能合約

? ? ? ? 開始前,必須有一個(gè)用于測(cè)試的區(qū)塊鏈智能合約,進(jìn)入以太坊官網(wǎng)提供的在線平臺(tái),地址為:https://remix.ethereum.org/,編寫測(cè)試合約。

java web3j4.8.4版本的使用記錄

????????編寫完成,編譯測(cè)試無誤后,部署合約,方法選擇如下

java web3j4.8.4版本的使用記錄

? ? ? ? 因?yàn)檫x擇通過web3的方式來發(fā)布合約,所以同步會(huì)要求登錄小狐貍(MetaMask),我這里事先就已經(jīng)添加好了幣安測(cè)試鏈,如果各位沒有添加的話,自己自行添加哈

java web3j4.8.4版本的使用記錄

1.3 合約轉(zhuǎn)化

? ? ? ? ?合約發(fā)布成功后,測(cè)試一下合約內(nèi)的方法是否可以正常使用,一切OK了以后,在remix中的編譯模塊內(nèi),將abi和bin保存放入本地文件中用于生成java文件。

java web3j4.8.4版本的使用記錄

java web3j4.8.4版本的使用記錄

說明一下哦,在生成java文件時(shí),本地要有web3j的資源文件,我事先已經(jīng)做好了準(zhǔn)備工作了,如果你們沒有的話,就自己查下哈。

進(jìn)入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 >web3j command line tools</a>,
 * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 
 * <a >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、測(cè)試合約方法的調(diào)用和合約事件監(jiān)聽

? ?說明:

? ? ? ? web3j通過rpc的方式建立連接,連接方式我測(cè)試時(shí),用了兩種方式,一種是http的方式調(diào)用合約的方法,websocket的方式調(diào)用的事件監(jiān)聽,兩種方式測(cè)試都是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("換成自己的測(cè)試錢包地址私鑰");
            BigInteger currentGasPrice = web3j.ethGasPrice().sendAsync().get().getGasPrice();
            EventTest eventTest = EventTest.load(token, web3j, credentials, new DefaultGasProvider() {
                /**
                 * 使用動(dòng)態(tài)獲取的 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;
        //實(shí)例化websocket
        WebSocketService webSocketService = new WebSocketService(wsurl,true);
        //建立連接
        webSocketService.connect();
        //實(shí)例化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("換成自己的測(cè)試錢包地址私鑰");
            BigInteger currentGasPrice = web3j.ethGasPrice().sendAsync().get().getGasPrice();
            EventTest eventTest = EventTest.load(token, web3j, credentials, new DefaultGasProvider() {
                *//**
                 * 使用動(dòng)態(tài)獲取的 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("換成自己的測(cè)試錢包地址私鑰");
            BigInteger currentGasPrice = client.ethGasPrice().sendAsync().get().getGasPrice();
            EventTest eventTest = EventTest.load(token, client, credentials, new DefaultGasProvider() {
                /**
                 * 使用動(dòng)態(tài)獲取的 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());
                        //解析時(shí)間返回的參數(shù)
                        EventValues eventValues = Contract.staticExtractEventParameters(EventTest.CHANGENAMEEVENT_EVENT, log);
                        for (Type nonIndexedValue : eventValues.getNonIndexedValues()) {
                            System.out.println(nonIndexedValue.getValue());
                        }
                    });
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}

事件測(cè)試結(jié)果

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,暫時(shí)完事了。

最后補(bǔ)充一下

如果沒有的rpc地址的,可以搜一下,也可以使用我上面的那個(gè)地址,不過僅限于測(cè)試用哦。文章來源地址http://www.zghlxwxcb.cn/news/detail-412833.html

到了這里,關(guān)于java web3j4.8.4版本的使用記錄的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【web3j】java通過web3j監(jiān)聽并解析合約中的事件(event/emit)

    ① 查詢鏈上數(shù)據(jù)用的rpc(本示例是binance的,測(cè)試網(wǎng)可以使用:https://data-seed-prebsc-2-s2.binance.org:8545) ② 自己還要有一個(gè)測(cè)試鏈上部署好的合約,合約中要有一個(gè)方法emit了事件。 ③ java依賴 一、 通過自己合約的abi和bin生成一個(gè)java文件,abi和bin可以在remix的compiler模塊中獲取,

    2024年02月09日
    瀏覽(19)
  • java使用web3j,部署智能合約在測(cè)試鏈上,并調(diào)用(萬字詳細(xì)教程)

    java使用web3j,部署智能合約在測(cè)試鏈上,并調(diào)用(萬字詳細(xì)教程)

    最近在學(xué)區(qū)塊鏈相關(guān),想做點(diǎn)自己感興趣的。網(wǎng)上關(guān)于這塊部分的坑也比較多,最近也是問了很多行業(yè)從事者才慢慢填坑,因此記錄下來分享一下。 錢包 :metemask、 solidity編譯器 :remix 、 java ide :idea。 智能合約編寫的我選擇在remix上方便,而且部署的時(shí)候不需要自定義gasP

    2024年01月16日
    瀏覽(25)
  • Java Web3j nonce 獲取

    Web3j 獲取 nonce 的參考代碼 獲取一個(gè) address nonce 值的時(shí)候,其中有一個(gè)參數(shù)為 DefaultBlockParameter,上面代碼中采用的是 DefaultBlockParameterName 類,它有 3 個(gè)值,分別為 EARLIEST ( \\\"earliest\\\" ) LATEST ( \\\"latest\\\" ) PENDING ( \\\"pending\\\" ) earliest:創(chuàng)世區(qū)塊 latest:最新區(qū)塊 (區(qū)塊鏈的頭號(hào)區(qū)塊) pending:

    2024年02月14日
    瀏覽(30)
  • Web3j使用教程(2)

    Web3j使用教程(2)

    首先安裝solc(用于編譯智能合約)和web3j命令行工具(用于打包智能合約) npm install -g solc web3j安裝地址:?Releases · web3j/web3j · GitHub,選擇對(duì)應(yīng)操作系統(tǒng) 首先準(zhǔn)備一個(gè)智能合約 Owner.sol,建議先在remix上測(cè)試一下Remix - Ethereum IDE 先編譯? solcjs Owner.sol --bin --abi --optimize -o . 然后

    2023年04月24日
    瀏覽(30)
  • java通過web3j獲取ETH交易明細(xì)

    ? ? 我們?cè)陧?xiàng)目里面如果想要得到用戶的ETH交易明細(xì)怎么做呢?有兩種方式: ? ?1、直接獲取ETH最新塊的交易明細(xì)。 ? ?2、通過塊獲取用戶的交易明細(xì)。 廢話不多說,直接貼代碼看了 ???????? 下面是項(xiàng)目的相關(guān)依賴:

    2024年02月05日
    瀏覽(22)
  • Java與智能合約交互(Web3j)- write函數(shù)

    說在前頭 Web3是一種新興的網(wǎng)絡(luò)概念,由于某些原因?qū)е挛覀兡軌蚪佑|到的相關(guān)技術(shù)知識(shí)實(shí)在有限,每當(dāng)我遇見技術(shù)瓶頸總是不能找到充足的資料,這也讓我萌生了填補(bǔ)這片空白知識(shí)的沖動(dòng)。 “Hello Web3” 這個(gè)專欄會(huì)盡力將我掌握的web3 知識(shí)分享給大家。如果分享的知識(shí)能幫助

    2023年04月08日
    瀏覽(27)
  • 【W(wǎng)EB3】如何使用Web3J庫開發(fā)應(yīng)用連接到以太坊區(qū)塊鏈網(wǎng)絡(luò)

    ? Web3j 是一個(gè)與以太坊智能合約交互并與以太坊節(jié)點(diǎn)集成的 Java 庫。它是高度模塊化、類型安全和反應(yīng)式的,專為以太坊上的 Java 和 Android 開發(fā)而構(gòu)建。Web3j 消除了編寫自定義集成代碼以連接到以太坊區(qū)塊鏈網(wǎng)絡(luò)的開銷。 通過 HTTP 和 IPC 實(shí)現(xiàn)完整的 Ethereum JSON-RPC客戶端 API,

    2024年02月02日
    瀏覽(34)
  • web3j的基礎(chǔ)用法-3ETH交易監(jiān)聽器

    web3j的基礎(chǔ)用法-3ETH交易監(jiān)聽器

    demo簡(jiǎn)單實(shí)現(xiàn)了4種 監(jiān)聽區(qū)塊 監(jiān)聽所有交易 監(jiān)聽待上鏈的交易 監(jiān)聽指定合約的交易事件(例如監(jiān)控大戶流轉(zhuǎn),實(shí)現(xiàn)跟單,拋售等后續(xù)邏輯) github 地址 https://github.com/jambestwick/we3jdemo

    2024年02月11日
    瀏覽(20)
  • web3j 引用報(bào)錯(cuò):okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)解決

    web3j 引用報(bào)錯(cuò):okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)解決

    在做區(qū)塊鏈開發(fā)時(shí)引用了web3j,而web3j中又引用了OKhttp,在程序發(fā)起請(qǐng)求時(shí)報(bào)錯(cuò)如下 我項(xiàng)目中引用的web3j包如下 其實(shí)具體web3j哪個(gè)版本感覺都有類似問題,我嘗試過4.6.3版本到5.0.0都會(huì)報(bào)上述錯(cuò)。然后看項(xiàng)目依賴發(fā)現(xiàn)引用的OKhttp版本是3.14.9,網(wǎng)上說要將OKhttp版本號(hào)更換到4.3.1以上

    2024年02月09日
    瀏覽(27)
  • Web3j 繼承StaticStruct的類所有屬性必須為Public <DynamicArray<StaticStruct>>

    Web3j 繼承StaticStruct的類所有屬性必須為Public,屬性的順序和數(shù)量必須和solidity 里面的struct 屬性相同,否則屬性少了或者多了的時(shí)候會(huì)出現(xiàn)錯(cuò)位 Web3j 繼承StaticStruct的類所有屬性不能為private,因?yàn)閣eb3j 是通過長(zhǎng)度去截取返回值解析成對(duì)應(yīng)的屬性進(jìn)行賦值的。要獲取一個(gè)list對(duì)象時(shí)

    2024年02月09日
    瀏覽(26)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包