【acuibc】conflux java sdk调用合约示例代码
package conflux.test;
import conflux.web3j.Cfx;
import conflux.web3j.Request;
import conflux.web3j.request.Epoch;
import conflux.web3j.request.LogFilter;
import conflux.web3j.response.BigIntResponse;
import conflux.web3j.response.Log;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
/**
*
* @author admin
  */
  public class ConfluxTest {
  
  /**
  
  * @param args the command line arguments
    */
    public static void main(String[] args) throws Exception {
//	final Cfx cfx = Cfx.create("http://mainnet-jsonrpc.conflux-chain.org:12537/");
//	
//	Request<BigInteger, BigIntResponse> request = cfx.getEpochNumber();
//	
//	BigInteger bi = request.sendAndGet();
//	System.out.println("纪元号epoch number: " + bi.toString());
//	
//	request = cfx.getGasPrice();
//	
//	bi = request.sendAndGet();
//	System.out.println("当前的gas价格(以Drip为单位): " + bi.toString());
//	
//	request = cfx.getBalance("0x1accC10CD15eb2B415b6dD1A4d23FBe695287615");
//	
//	bi = request.sendAndGet();
//	System.out.println("帐户余额: " + bi.toString());
//	
//	Request<String, StringResponse> request2 = cfx.getBestBlockHash();
//	String str = request2.sendAndGet();
//	System.out.println("返回最佳区块的哈希值: " + bi.toString());
//	
//	request = cfx.getNonce("0x1accC10CD15eb2B415b6dD1A4d23FBe695287615");
//	bi = request.sendAndGet();
//	System.out.println("交易序列号Nonce: " + bi.toString());
//	ContractCall call = new ContractCall(cfx, "0x8ff10e5fb7a751b40d4a4bb6f792985003b8ed65");
//	call.buildFrom("0x1accC10CD15eb2B415b6dD1A4d23FBe695287615")
//		.buildGasLimit(new BigInteger("10000000")).buildGasPrice(new BigInteger("1"));
//	
//	Request<UsedGasAndCollateral, UsedGasAndCollateralResponse> req = call.estimateGasAndCollateral("getScore", org.web3j.abi.datatypes.Utf8String.DEFAULT);
//
//	UsedGasAndCollateral xx = req.sendAndGet();
//	System.out.println("xx=" + xx.toString());
//
//	Request<String, StringResponse> req2 = call.call("getScore", new org.web3j.abi.datatypes.Utf8String("0x1accC10CD15eb2B415b6dD1A4d23FBe695287615"));
//	String result = req2.sendAndGet();
//	
//	System.out.println("yy: " + result);
final Cfx cfx = Cfx.create("http://mainnet-jsonrpc.conflux-chain.org:12537/");
    
    Request<BigInteger, BigIntResponse> req = cfx.getBalance("0x18549f607b2023585d04cbb72eb7d05b4c980355");
    
    System.out.println(req.sendAndGet().toString());
    
    LogFilter filter = new LogFilter();
//        filter.setAddress(Arrays.asList("0x18549f607b2023585d04cbb72eb7d05b4c980355"));
filter.setFromEpoch(Epoch.numberOf(2025456));
filter.setToEpoch(Epoch.numberOf(2025656));
//        filter.setLimit(20000l);
Request<List
System.out.println("getMethod=" + req2.getMethod());
System.out.println("getId=" + req2.getId());
System.out.println("getJsonrpc=" + req2.getJsonrpc());
List
System.out.println("logs.size=" + logs.size());
for(Log log : logs) {
String address1 = log.getAddress();
String data = log.getData();
System.out.println("address=" + log.getAddress());
    System.out.println("data=" + log.getData());
    System.out.println("getEpochNumber=" + log.getEpochNumber().orElse(BigInteger.ONE));
    List<String> topics = log.getTopics();
    for(String topic : topics) {
        System.out.println("topic=" + topic);
    }
    System.out.println("transactionHash=" + log.getTransactionHash());
    System.out.println("————————————————————————————————————————————————————");
}
`
//	Account account = Account.create(cfx, "0x7e97b6aa0941c3323557cea950c85ec8c4be9fd36936f74dc053c6a5dcf24c4f");
//	
//        // 发布合约
//	String ret = account.deploy(new BigInteger("1000000"), "6080604052348015600f57600080fd5b5060a28061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063bb4e3f4d14602d575b600080fd5b605260048036036040811015604157600080fd5b5060ff813581169160200135166068565b6040805160ff9092168252519081900360200190f35b019056fea26469706673582212201c8bf83ca9fda2bf3f0f1f6026e9cc721739e7c5d0b87a940c939bc066bb727264736f6c634300060a0033");
//	
//	// 调用合约函数
//	ret = account.call("0x848794494875da322c2ff0ebb5c984143aafa404",
//		new BigInteger("1000000"),
//		"add",
//		new org.web3j.abi.datatypes.generated.Uint8(BigInteger.valueOf(10l)), new org.web3j.abi.datatypes.generated.Uint8(BigInteger.valueOf(20l)));
//
//        // 转账
//	ret = account.transfer("0x129190f3477eb36e964c51b03a78a4a51b2b41f9", CfxUnit.cfx2Drip(10));
//	BigInteger currentEpoch = cfx.getEpochNumber().sendAndGet();
//	RawTransaction tx = RawTransaction.create(cfx.getNonce("0x1d66b984836ff8ce4b3c61f7b44fa4e753fc5dc6").sendAndGet(),
//		BigInteger.valueOf(21000), "0x129190f3477eb36e964c51b03a78a4a51b2b41f9", BigInteger.TEN, BigInteger.ZERO, currentEpoch, null);
//	tx.setGasPrice(CfxUnit.DEFAULT_GAS_PRICE.add(BigInteger.TEN).add(BigInteger.ONE));
//	String ret = account.mustSend(tx);
//	Function function = new Function("add", Arrays.asList(new org.web3j.abi.datatypes.Uint(new BigInteger("2")), new org.web3j.abi.datatypes.Uint(new BigInteger("2"))), Collections.emptyList());
//	System.out.println("data=" + FunctionEncoder.encode(function));
//
//	Account account = Account.create(cfx, "0xa83e1690531f17c2226844217c6e23c518164c43dc651747b2e69e47d6d280e0");
//	String ret = account.call("0x8a132b42f67e3b0ceb7c8d7444b71703d299fab9",
//		new BigInteger("1000000"),
//		BigInteger.ZERO,
//		"0xbb4e3f4d000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000014");
//	
//	System.out.println("ret=" + ret);
//	
//	Function function = new Function("add", Arrays.asList(new org.web3j.abi.datatypes.Int(new BigInteger("10")), new org.web3j.abi.datatypes.Int(new BigInteger("20"))), Collections.emptyList());
//	System.out.println("data=" + FunctionEncoder.encode(function));
//final Function function = new Function(
//                "add",
//                Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint8(BigInteger.valueOf(10l)),
//                new org.web3j.abi.datatypes.generated.Uint8(BigInteger.valueOf(20l))),
//                Collections.<TypeReference<?>>emptyList());
//System.out.println("data=" + FunctionEncoder.encode(function));
}
}