• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Transaction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.web3j.protocol.core.methods.request.Transaction的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Transaction类属于org.web3j.protocol.core.methods.request包,在下文中一共展示了Transaction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: callHash

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
private byte[] callHash(String name, Type...parameters) throws InterruptedException, ExecutionException {

        Function function = new Function(name,
            Arrays.asList(parameters),
            Arrays.asList(new TypeReference<Bytes32>() {})
        );
        String encodedFunction = FunctionEncoder.encode(function);

        TransactionManager transactionManager = cfg.getTransactionManager(cfg.getMainAddress());
        String channelLibraryAddress = contractsProperties.getAddress().get("ChannelLibrary").toString();
        org.web3j.protocol.core.methods.response.EthCall ethCall = web3j.ethCall(
            Transaction.createEthCallTransaction(
                transactionManager.getFromAddress(), channelLibraryAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

        String value = ethCall.getValue();
        List<Type> list = FunctionReturnDecoder.decode(value, function.getOutputParameters());
        return ((Bytes32) list.get(0)).getValue();
    }
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:21,代码来源:HashTest.java


示例2: detectCurrentParams

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
public TransactionParams detectCurrentParams(BigInteger maxGasPrice, BigInteger maxGasLimit, FunctionCall call, BigInteger value) throws IOException {
    BigInteger nonce = getNonce();
    BigInteger blockGasLimit = web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send().getBlock().getGasLimit();
    
    EthEstimateGas gas = web3j.ethEstimateGas(new Transaction(getFromAddress(), nonce, maxGasPrice, blockGasLimit, call.contractAddress, value, call.data)).send();
    BigInteger actualGasLimit = maxGasLimit;

    if (rpc.isFailFast()) {
        CallUtil.checkError(gas, call.toString());
    } 
    if (gas.getError() == null) {
        BigInteger amountUsed = gas.getAmountUsed();
        if (amountUsed.compareTo(maxGasLimit) >= 0) {
            throw new IllegalStateException(String.format("Estimate out of gas, used: %s, limit: %s, block limit: %s, from: %s, %s", amountUsed, maxGasLimit, blockGasLimit, getFromAddress(), call));
        }
        BigInteger estimateAmount = amountUsed.shiftLeft(1);
        if (estimateAmount.compareTo(maxGasLimit) < 0) {
            actualGasLimit = estimateAmount;
        }
    } else {
        log.warn("Transaction will fail from {}: {}", getFromAddress(), call);
    }
    EthGasPrice gasPrice = web3j.ethGasPrice().send();
    CallUtil.checkError(gasPrice);
    BigInteger actualGasPrice = gasPrice.getGasPrice();
    if (actualGasPrice.compareTo(maxGasPrice) > 0) {
        log.warn("Configured gas price is less than median. Median: {}, configured: {}", actualGasPrice, maxGasPrice);
        actualGasPrice = maxGasPrice;
    }
    return new TransactionParams(nonce, actualGasPrice, actualGasLimit);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:32,代码来源:ThreadsafeTransactionManager.java


示例3: transferFromCoinbaseAndWait

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
/**
 * Transfers the specified amount of Wei from the coinbase to the specified account.
 * The method waits for the transfer to complete using method {@link waitForReceipt}.  
 */
public static TransactionReceipt transferFromCoinbaseAndWait(Web3j web3j, String to, BigInteger amountWei) 
		throws Exception 
{
	String coinbase = getCoinbase(web3j).getResult();
	BigInteger nonce = getNonce(web3j, coinbase);
	// this is a contract method call -> gas limit higher than simple fund transfer
	BigInteger gasLimit = Web3jConstants.GAS_LIMIT_ETHER_TX.multiply(BigInteger.valueOf(2)); 
	Transaction transaction = Transaction.createEtherTransaction(
			coinbase, 
			nonce, 
			Web3jConstants.GAS_PRICE, 
			gasLimit, 
			to, 
			amountWei);

	EthSendTransaction ethSendTransaction = web3j
			.ethSendTransaction(transaction)
			.sendAsync()
			.get();

	String txHash = ethSendTransaction.getTransactionHash();
	
	return waitForReceipt(web3j, txHash);
}
 
开发者ID:matthiaszimmermann,项目名称:web3j_demo,代码行数:29,代码来源:Web3jUtils.java


示例4: callSmartContractFunction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
private String callSmartContractFunction(
        Function function, String contractAddress) throws Exception {
    String encodedFunction = FunctionEncoder.encode(function);

    org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
            Transaction.createEthCallTransaction(
                    ALICE.getAddress(), contractAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

    return response.getValue();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:13,代码来源:HumanStandardTokenIT.java


示例5: sendTransaction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
private String sendTransaction() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());

    Transaction transaction = Transaction.createContractTransaction(
            ALICE.getAddress(),
            nonce,
            GAS_PRICE,
            GAS_LIMIT,
            BigInteger.ZERO,
            getFibonacciSolidityBinary());

    org.web3j.protocol.core.methods.response.EthSendTransaction
            transactionResponse = web3j.ethSendTransaction(transaction)
            .sendAsync().get();

    return transactionResponse.getTransactionHash();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:18,代码来源:DeployContractIT.java


示例6: sendCreateContractTransaction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
private String sendCreateContractTransaction() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());

    String encodedConstructor =
            FunctionEncoder.encodeConstructor(Collections.singletonList(new Utf8String(VALUE)));

    Transaction transaction = Transaction.createContractTransaction(
            ALICE.getAddress(),
            nonce,
            GAS_PRICE,
            GAS_LIMIT,
            BigInteger.ZERO,
            getGreeterSolidityBinary() + encodedConstructor);

    org.web3j.protocol.core.methods.response.EthSendTransaction
            transactionResponse = web3j.ethSendTransaction(transaction)
            .sendAsync().get();

    return transactionResponse.getTransactionHash();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:21,代码来源:GreeterContractIT.java


示例7: testPersonalSendTransaction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
@Test
public void testPersonalSendTransaction() throws Exception {
    web3j.personalSendTransaction(
            new Transaction(
                    "FROM",
                    BigInteger.ONE,
                    BigInteger.TEN,
                    BigInteger.ONE,
                    "TO",
                    BigInteger.ZERO,
                    "DATA"
            ),
            "password"
    ).send();

    //CHECKSTYLE:OFF
    verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"personal_sendTransaction\",\"params\":[{\"from\":\"FROM\",\"to\":\"TO\",\"gas\":\"0x1\",\"gasPrice\":\"0xa\",\"value\":\"0x0\",\"data\":\"0xDATA\",\"nonce\":\"0x1\"},\"password\"],\"id\":1}");
    //CHECKSTYLE:ON
}
 
开发者ID:web3j,项目名称:web3j,代码行数:20,代码来源:RequestTest.java


示例8: testEthSendTransaction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
@Test
public void testEthSendTransaction() throws Exception {
    web3j.ethSendTransaction(new Transaction(
            "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
            BigInteger.ONE,
            Numeric.toBigInt("0x9184e72a000"),
            Numeric.toBigInt("0x76c0"),
            "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
            Numeric.toBigInt("0x9184e72a"),
            "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb"
                    + "970870f072445675058bb8eb970870f072445675")).send();

    //CHECKSTYLE:OFF
    verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendTransaction\",\"params\":[{\"from\":\"0xb60e8dd61c5d32be8058bb8eb970870f07233155\",\"to\":\"0xb60e8dd61c5d32be8058bb8eb970870f07233155\",\"gas\":\"0x76c0\",\"gasPrice\":\"0x9184e72a000\",\"value\":\"0x9184e72a\",\"data\":\"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675\",\"nonce\":\"0x1\"}],\"id\":1}");
    //CHECKSTYLE:ON
}
 
开发者ID:web3j,项目名称:web3j,代码行数:17,代码来源:RequestTest.java


示例9: transferWei

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
String transferWei(String from, String to, BigInteger amountWei) throws Exception {
	BigInteger nonce = getNonce(from);
	Transaction transaction = Transaction.createEtherTransaction(
			from, nonce, Web3jConstants.GAS_PRICE, Web3jConstants.GAS_LIMIT_ETHER_TX, to, amountWei);

	EthSendTransaction ethSendTransaction = web3j.ethSendTransaction(transaction).sendAsync().get();
	System.out.println("transferEther. nonce: " + nonce + " amount: " + amountWei + " to: " + to);

	String txHash = ethSendTransaction.getTransactionHash(); 
	waitForReceipt(txHash);
	
	return txHash;
}
 
开发者ID:matthiaszimmermann,项目名称:web3j_demo,代码行数:14,代码来源:AbstractEthereumTest.java


示例10: callSmartContractFunction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
private String callSmartContractFunction(
        org.web3j.abi.datatypes.Function function, String contractAddress, Wallet wallet) throws Exception {
    String encodedFunction = FunctionEncoder.encode(function);

    org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
            Transaction.createEthCallTransaction(wallet.address, contractAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

    return response.getValue();
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:12,代码来源:TokenRepository.java


示例11: transfer

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
public static String transfer(String from, String to, int amount, Unit unit) throws InterruptedException, ExecutionException {
	BigInteger nonce = getNonce(from);
	BigInteger weiAmount = Convert.toWei(BigDecimal.valueOf(amount), unit).toBigInteger();
	Transaction transaction = new Transaction(from, nonce, GAS_PRICE_DEFAULT, GAS_LIMIT_DEFAULT, to, weiAmount, null);
	EthSendTransaction txRequest = getWeb3j().ethSendTransaction(transaction).sendAsync().get();
	return txRequest.getTransactionHash();
}
 
开发者ID:BSI-Business-Systems-Integration-AG,项目名称:trading-network,代码行数:8,代码来源:Web3jHelper.java


示例12: transferEther

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
public static CompletableFuture<EthSendTransaction> transferEther(String from, String to, double ethAmount) {
    return web3j.ethGetTransactionCount(from, DefaultBlockParameterName.LATEST).sendAsync()
            .thenCompose(transactionCount -> parity.ethSendTransaction(
                            Transaction.createEtherTransaction(from, transactionCount.getTransactionCount(),
                                    GAS_PRICE, GAS_LIMIT, to, toWei(ethAmount))).sendAsync()
            );
}
 
开发者ID:papyrusglobal,项目名称:smartcontracts,代码行数:8,代码来源:PapyrusUtils.java


示例13: estimateGas

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
private BigInteger estimateGas(String encodedFunction) throws Exception {
    EthEstimateGas ethEstimateGas = web3j.ethEstimateGas(
            Transaction.createEthCallTransaction(ALICE.getAddress(), null, encodedFunction))
            .sendAsync().get();
    // this was coming back as 50,000,000 which is > the block gas limit of 4,712,388
    // see eth.getBlock("latest")
    return ethEstimateGas.getAmountUsed().divide(BigInteger.valueOf(100));
}
 
开发者ID:web3j,项目名称:web3j,代码行数:9,代码来源:EventFilterIT.java


示例14: sendTransaction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
private String sendTransaction(
        Credentials credentials, String contractAddress, BigInteger gas,
        String encodedFunction) throws Exception {
    BigInteger nonce = getNonce(credentials.getAddress());
    Transaction transaction = Transaction.createFunctionCallTransaction(
            credentials.getAddress(), nonce, Transaction.DEFAULT_GAS, gas, contractAddress,
            encodedFunction);

    org.web3j.protocol.core.methods.response.EthSendTransaction transactionResponse =
            web3j.ethSendTransaction(transaction).sendAsync().get();

    assertFalse(transactionResponse.hasError());

    return transactionResponse.getTransactionHash();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:16,代码来源:EventFilterIT.java


示例15: callSmartContractFunction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
private String callSmartContractFunction(
        Function function, String contractAddress) throws Exception {

    String encodedFunction = FunctionEncoder.encode(function);

    org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
            Transaction.createEthCallTransaction(
                    ALICE.getAddress(), contractAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

    return response.getValue();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:14,代码来源:DeployContractIT.java


示例16: buildTransaction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
@Override
public Transaction buildTransaction() {
    return Transaction.createContractTransaction(
            validAccount(),
            BigInteger.ZERO,  // nonce
            Transaction.DEFAULT_GAS,
            validContractCode()
    );
}
 
开发者ID:web3j,项目名称:web3j,代码行数:10,代码来源:TestnetConfig.java


示例17: sendTransaction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
@Override
public EthSendTransaction sendTransaction(
        BigInteger gasPrice, BigInteger gasLimit, String to,
        String data, BigInteger value)
        throws IOException {

    Transaction transaction = new Transaction(
            getFromAddress(), null, gasPrice, gasLimit, to, value, data);

    return web3j.ethSendTransaction(transaction)
            .send();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:13,代码来源:ClientTransactionManager.java


示例18: executeCall

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
/**
 * Execute constant function call - i.e. a call that does not change state of the contract
 *
 * @param function to call
 * @return {@link List} of values returned by function call
 */
private List<Type> executeCall(
        Function function) throws IOException {
    String encodedFunction = FunctionEncoder.encode(function);
    org.web3j.protocol.core.methods.response.EthCall ethCall = web3j.ethCall(
            Transaction.createEthCallTransaction(
                    transactionManager.getFromAddress(), contractAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .send();

    String value = ethCall.getValue();
    return FunctionReturnDecoder.decode(value, function.getOutputParameters());
}
 
开发者ID:web3j,项目名称:web3j,代码行数:19,代码来源:Contract.java


示例19: personalSendTransaction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
@Override
public Request<?, EthSendTransaction> personalSendTransaction(
        Transaction transaction, String passphrase) {
    return new Request<>(
            "personal_sendTransaction",
            Arrays.asList(transaction, passphrase),
            web3jService,
            EthSendTransaction.class);
}
 
开发者ID:web3j,项目名称:web3j,代码行数:10,代码来源:JsonRpc2_0Admin.java


示例20: ethSendTransaction

import org.web3j.protocol.core.methods.request.Transaction; //导入依赖的package包/类
@Override
public Request<?, org.web3j.protocol.core.methods.response.EthSendTransaction>
        ethSendTransaction(
        Transaction transaction) {
    return new Request<>(
            "eth_sendTransaction",
            Arrays.asList(transaction),
            web3jService,
            org.web3j.protocol.core.methods.response.EthSendTransaction.class);
}
 
开发者ID:web3j,项目名称:web3j,代码行数:11,代码来源:JsonRpc2_0Web3j.java



注:本文中的org.web3j.protocol.core.methods.request.Transaction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SessionAlarmService类代码示例发布时间:2022-05-22
下一篇:
Java TileEntityDropper类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap