package main import ( "context" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/web3/api" "math/big" "strconv" "time" ) func PING() (string, error) { currentTime := time.Now() timeString := currentTime.Format("2006-01-02 15:04:05.123") return timeString, nil } func main() { api.PrintTime("GO") ipcPath := "\\\\.\\pipe\\geth.ipc" // 使用 IPC 连接到以太坊节点 client, err := rpc.Dial(ipcPath) if err != nil { api.PrintTime("无法连接到以太坊节点:", err) } // 连接成功,可以使用 client 进行后续操作 // eth_call var result string //arg := map[string]interface{}{ // "from": "0x746Fe602eD945378478523D53007B1c9d14037Ff", // "to": "0x746Fe602eD945378478523D53007B1c9d14037Ff", // "data": "0x", // "value": hexutil.Uint64(0), // "gas": hexutil.Uint64(100000), // "gasPrice": hexutil.Uint64(100000), //} //api.PrintTime("eth_call") //err = client.CallContext(context.Background(), &result, "eth_call", arg, "pending") //api.PrintTime(result) // //err = client.CallContext(context.Background(), &result, "zdy_getPrvKey", "0x000000FB5e4fbEE939625B0099288bCF51Ed6FA1") //if err != nil { // log.Fatal("无法获取信息:", err) //} // //fmt.Println("当前结果:", result) //err = client.CallContext(context.Background(), &result, "zdy_unLockAllAccount") //if err != nil { // log.Fatal("无法获取信息:", err) //} // //fmt.Println("当前结果:", result) // //arg = map[string]interface{}{ // "from": "0x000000fb5e4fbee939625b0099288bcf51ed6fa1", // "to": "0x0000000000000000000000000000000000000000", // "data": "0x", // "value": hexutil.Uint64(0), // "nonce": hexutil.Uint64(38), // "gas": hexutil.Uint64(100000), // "gasPrice": hexutil.Uint64(10000000000), // "chainID": "0x45c", //} //err = client.CallContext(context.Background(), &result, "eth_sendTransaction", arg) //if err != nil { // log.Fatal("无法获取信息:", err) //} // //fmt.Println("当前结果:", result) toAddress := "0x0000000000000000000000000000000000000410" gasPrice := big.NewInt(50000000410) gasLimit := uint64(30000) value := big.NewInt(0) // 1 ETH nonce := uint64(87) data := "" // 获取私钥对象 privateKeyHex := "d18f844b8ff00c723592257d57c41b2ebef0b197c8daf4f8a5909ffd18165b8d" _, rawHash, err := api.SignTransaction(nonce, toAddress, value, gasLimit, gasPrice, data, privateKeyHex) //api.SpeedTest(PING) //api.SpeedTest(client.CallContext, context.Background(), &result, "zdy_ping") //api.PrintTime(result) err = client.CallContext(context.Background(), &result, "eth_blockNumber") blockNumber, _ := strconv.ParseInt(result, 0, 64) api.PrintTime(blockNumber) for { err = client.CallContext(context.Background(), &result, "eth_blockNumber") nowBlockNumber, _ := strconv.ParseInt(result, 0, 64) if nowBlockNumber > blockNumber { api.PrintTime(nowBlockNumber) break } } // //err = client.CallContext(context.Background(), &result, "eth_sendRawTransaction", rawHash) //api.PrintTime(result) // //gasLimit = uint64(100002) // //// 获取私钥对象 // //_, rawHash, err = api.SignTransaction(nonce, toAddress, value, gasLimit, gasPrice, data, privateKeyHex) //err = client.CallContext(context.Background(), &result, "zdy_sendRawTransaction", rawHash) //api.PrintTime(result) //api.PrintTime("zdy_sendRawTransaction") // //client.CallContext(context.Background(), &result, "zdy_sendRawTransaction", rawHash) //api.PrintTime("zdy_sendRawTransaction", result) api.PrintTime("eth_newPendingTransactionFilter") client.CallContext(context.Background(), &result, "eth_newPendingTransactionFilter", rawHash) api.PrintTime("eth_newPendingTransactionFilter", result) api.SpeedTest(log.Info, "abc123") }