Categorygithub.com/gnc-project/GNC-go
modulepackage
1.0.2
Repository: https://github.com/gnc-project/gnc-go.git
Documentation: pkg.go.dev

# README

GNC-go

Examples are in the test folder

Connect node

    client, err := ethclient.Dial("http://localhost:1234")

Send transaction (signature mode)

Construct fromAddress by privatekey

//0xf5403E4F120901407eF221E2419583D1F3556953
    privateKey, err := crypto.HexToECDSA("b77de610fb69f929f9ce38e07bc003bb8dfffc9024c0af0da26ab2d0a052492e")
    if err != nil {
        log.Fatal(err)
    }
    publicKey := privateKey.Public()
    publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
    if !ok {
        log.Fatal("cannot assert type: publicKey is not of type *ecdsa.PublicKey")
    }
    fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)

Construct toAddress

   toAddress := common.HexToAddress("GNC6cBe9DF6DF54281D363e7a5e1790dc66212438C7")

set value

    value := decimal.NewFromFloat(0.1)//this is value you want to send

    decimals := decimal.NewFromFloat(math.Pow10(18))
    amount:=value.Mul(decimals)//Authentic value 

set gasPrice and gaslimit

//gasPrice
    gasPrice, err := client.SuggestGasPrice(context.Background())
    if err != nil {
        log.Fatal(err)
    }
//gaslimit
    gas:=uint64(21000)

set nonce

//nonce
    nonce, err := client.PendingNonceAt(context.Background(), fromAddress)

Construct transaction

 //"github.com/gnc-project/GNC-go/core/types"
    tx := types.NewTransaction(nonce, toAddress, amount.BigInt(),gas, gasPrice, data)

Inquire chainID

   chainID, err := client.NetworkID(context.Background())

Sign transaction

    signedTx, err := types.SignTx(tx, types.NewEIP155Signer(big.NewInt(chainID.Int64())), privateKey)

send signatureTx

//"github.com/gnc-project/GNC-go/core/types"
    err = client.SendRawTransaction(context.Background(), signedTx)

Send transaction (unlock mode)

    fromAddress := common.HexToAddress("GNC0d8c6aba421723b3bce849c70c06592f696e4399")
    toAddress := common.HexToAddress("GNC6cBe9DF6DF54281D363e7a5e1790dc66212438C7")

    //Inquire nonce
    nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
        if err != nil {
            log.Fatal(err)
        }
    //Construct transaction
    tx:=types.SendTxArgs{
        From:       fromAddress,
        To :        toAddress,
        Gas:        hexutil.Uint64(21000),
        GasPrice:   hexutil.Big(*big.NewInt(6000000000)),
        Value:      hexutil.Big(*big.NewInt(1)),
        Nonce:      hexutil.Uint64(nonce),
 
        Data:      hexutil.Bytes([]byte{}),
        Type:      0,
    }
    //send transaction
//"github.com/gnc-project/GNC-go/core/types"
        hash,err:=client.SendTransaction(context.Background(),tx)
        if err != nil {
            log.Fatal(err)
        }

Inquire transaction

	transaction,isPending,err:=client.TransactionByHash(context.Background(),TransactionHash)
	if err != nil {
        log.Fatal(err)
    }

Inquire Balance

	Address := common.HexToAddress("GNC86056D210eA7Bc23337aCaBE96dE275E584a67ce")
	balance,err:=client.BalanceAt(context.Background(),Address,nil)
	if err != nil {
        log.Fatal(err)
    }

Inquire block

	blockHash := common.HexToHash("0x18c8c36ac3c285d7b276e59b1988d0632aec58ee7f70faa17cfe74de0c5484b5")
    block,err=client.BlockByHash(context.Background(),blockHash)
    //or ByNumber
	// block,err=client.BlockByNumber(context.Background(),big.NewInt(25591))

# Packages

Package common contains various helper functions.
No description provided by the author
No description provided by the author
Package ethclient provides a client for the Ethereum RPC API.
Package log15 provides an opinionated, simple toolkit for best-practice logging that is both human and machine readable.
Package p2p implements the Ethereum p2p network protocols.
No description provided by the author
Package rlp implements the RLP serialization format.
Package rpc implements bi-directional JSON-RPC 2.0 on multiple transports.
No description provided by the author

# Variables

NotFound is returned by API methods if the requested item does not exist.

# Structs

CallMsg contains parameters for contract calls.
FilterQuery contains options for contract log filtering.
SyncProgress gives progress indications when the node is synchronising with the Ethereum network.

# Interfaces

ChainReader provides access to the blockchain.
ChainStateReader wraps access to the state trie of the canonical blockchain.
ChainSyncReader wraps access to the node's current sync status.
A ContractCaller provides contract calls, essentially transactions that are executed by the EVM but not mined into the blockchain.
GasEstimator wraps EstimateGas, which tries to estimate the gas needed to execute a specific transaction based on the pending state.
GasPricer wraps the gas price oracle, which monitors the blockchain to determine the optimal gas price given current fee market conditions.
LogFilterer provides access to contract log events using a one-off query or continuous event subscription.
PendingContractCaller can be used to perform calls against the pending state.
A PendingStateEventer provides access to real time notifications about changes to the pending state.
A PendingStateReader provides access to the pending state, which is the result of all known executable transactions which have not yet been included in the blockchain.
Subscription represents an event subscription where events are delivered on a data channel.
TransactionReader provides access to past transactions and their receipts.
TransactionSender wraps transaction sending.