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

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# 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))