package com.example.demo.test;
import com.example.demo.util.Constants;
import org.web3j.abi.FunctionEncoder;
import org.web3j.abi.FunctionReturnDecoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameterName;
import org.web3j.protocol.core.methods.request.Transaction;
import org.web3j.protocol.core.methods.response.EthCall;
import org.web3j.protocol.http.HttpService;
import java.util.Arrays;
import java.util.List;
public class TransactionGetTest {
public static void main(String[] args) throws Exception {
Web3j web3j = Web3j.build(new HttpService()); // defaults to http://localhost:8545/
/*
* String name 函数名字
* List<Type> inputParameters 入口参数
* List<TypeReference<?>> outputParameters 出口参数
*/
Function function = new Function("get",
Arrays.<Type>asList(),
Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {
}));
// encode the function
String encodedFunction = FunctionEncoder.encode(function);
/*
* String from null(optional)
* String to 合约地址
* String data ABI
*/
EthCall response = web3j.ethCall(Transaction.createEthCallTransaction(null, Constants.ADDRESS, encodedFunction), DefaultBlockParameterName.LATEST).send();
// get result
List<Type> result = FunctionReturnDecoder.decode(response.getValue(), function.getOutputParameters());
int data = Integer.parseInt(result.get(0).getValue().toString());
System.out.println("data = " + data);
}
}
您正在查看: Surou 发布的文章
web3j.ethCall 测试
由Golang实现的多币种HD钱包
https://github.com/foxnut/go-hdwallet
supported coins
- BTC
- LTC
- DOGE
- DASH
- ETH
- ETC
- BCH
- QTUM
- USDT
- IOST
- USDC
install
go get -v -u github.com/foxnut/go-hdwallet
example
package main
import (
"fmt"
"github.com/foxnut/go-hdwallet"
)
var (
mnemonic = "range sheriff try enroll deer over ten level bring display stamp recycle"
)
func main() {
master, err := hdwallet.NewKey(
hdwallet.Mnemonic(mnemonic),
)
if err != nil {
panic(err)
}
// BTC: 1AwEPfoojHnKrhgt1vfuZAhrvPrmz7Rh4
wallet, _ := master.GetWallet(hdwallet.CoinType(hdwallet.BTC), hdwallet.AddressIndex(1))
address, _ := wallet.GetAddress()
addressP2WPKH, _ := wallet.GetKey().AddressP2WPKH()
addressP2WPKHInP2SH, _ := wallet.GetKey().AddressP2WPKHInP2SH()
fmt.Println("BTC: ", address, addressP2WPKH, addressP2WPKHInP2SH)
// BCH: 1CSBT18sjcCwLCpmnnyN5iqLc46Qx7CC91
wallet, _ = master.GetWallet(hdwallet.CoinType(hdwallet.BCH))
address, _ = wallet.GetAddress()
addressBCH, _ := wallet.GetKey().AddressBCH()
fmt.Println("BCH: ", address, addressBCH)
// LTC: LLCaMFT8AKjDTvz1Ju8JoyYXxuug4PZZmS
wallet, _ = master.GetWallet(hdwallet.CoinType(hdwallet.LTC))
address, _ = wallet.GetAddress()
fmt.Println("LTC: ", address)
// DOGE: DHLA3rJcCjG2tQwvnmoJzD5Ej7dBTQqhHK
wallet, _ = master.GetWallet(hdwallet.CoinType(hdwallet.DOGE))
address, _ = wallet.GetAddress()
fmt.Println("DOGE:", address)
// ETH: 0x37039021cBA199663cBCb8e86bB63576991A28C1
wallet, _ = master.GetWallet(hdwallet.CoinType(hdwallet.ETH))
address, _ = wallet.GetAddress()
fmt.Println("ETH: ", address)
// ETC: 0x480C69E014C7f018dAbF17A98273e90f0b0680cf
wallet, _ = master.GetWallet(hdwallet.CoinType(hdwallet.ETC))
address, _ = wallet.GetAddress()
fmt.Println("ETC: ", address)
}以太坊观察者
https://github.com/HydroProtocol/ethereum-watcher
ethereum-watcher是用Golang编写的以太坊区块链的事件监听器。使用以太坊观察器,您可以监视和跟踪以太坊区块链上发生的当前或历史事件。
背景
与以太坊区块链交互的许多应用程序需要知道链上何时发生特定动作,但无法直接访问链上数据。ethereum-watcher充当应用程序和链之间的接口:从区块链收集指定的数据,以便应用程序可以与链上事件进行更无缝的交互。
特征
插件友好。您可以轻松地向以太坊观察者添加一个插件,以侦听任何类型的链上事件。
叉公差。如果发生派生,则将一条还原消息发送给订户。
最新回复
fzd: 请问这个解决了吗
StarkWare explained: layer 2 solution provider of dYdX and iMMUTABLE R11; BitKeep News: [...]Layer 2: https://...
一文读懂 StarkWare:dYdX 和 Immutable 背后的 L2 方案 R11; BitKeep 博客: [...]Layer 2:Comparing Laye...
http://andere.strikingly.com/: Regards, Great stuff!
surou: 需要先执行提案合约申请,等待出块节点地址同意后,才会进...
heco: WARN [11-19|11:26:09.459] N...
P: 你好,我在heco链上遇到了“tx fee excee...
Peng: 楼主安装成功了吗?我正在同步区块链,一天了,差不多才同...
joyhu: 你好,请问下安装好之后如何获取到bee.yaml配置文...
kaka: 支票最终怎么提币呢?
归档
September 2026July 2026June 2026May 2026April 2026March 2026February 2026January 2026December 2025November 2025October 2025September 2025August 2025July 2025June 2025May 2025April 2025March 2025February 2025January 2025December 2024November 2024October 2024September 2024August 2024July 2024June 2024May 2024April 2024March 2024January 2024December 2023November 2023October 2023September 2023August 2023July 2023June 2023April 2023March 2023February 2023January 2023December 2022November 2022October 2022August 2022July 2022June 2022May 2022March 2022February 2022January 2022December 2021November 2021October 2021September 2021August 2021July 2021June 2021May 2021April 2021March 2021February 2021January 2021December 2020November 2020October 2020September 2020July 2020June 2020May 2020April 2020March 2020February 2020January 2020December 2019November 2019October 2019September 2019August 2019July 2019June 2019May 2019April 2019March 2019February 2019January 2019December 2018November 2018October 2018September 2018August 2018July 2018June 2018