Bitcoin Forum
July 08, 2024, 10:40:31 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [go-ethereum] Ошибка при при переводе токенов  (Read 131 times)
expressphpcode (OP)
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile
October 19, 2018, 07:43:33 PM
Last edit: October 20, 2018, 06:10:04 AM by expressphpcode
 #1

Здравствуйте уважаемые кодеры!. Кто работал с (go-ethereum) возможно вы сталкивались с данной ошибкой (Attempting to run transaction which calls a contract function, but recipient address 0xefdb9e216f42424b54eb591ad086f20165830ad7 is not a contract address), значение данной ошибки мне понятно, deploy контракта выполнен, но суть в том что я все делаю по примере https://www.youtube.com/watch?v=-Epg5Ub-fA0&t=17s:

Code:
package main

import (
"context"
"crypto/ecdsa"
"fmt"
"log"
"math/big"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/ethclient"
)

func main() {
client, err := ethclient.Dial("http://127.0.0.1:7545")
if err != nil {
log.Fatal(err)
}

privateKey, err := crypto.HexToECDSA("51b24d0a29940af4b7f346f23b840c4c45d50ab0bb34d821cc41e766fc189016")
if err != nil {
log.Fatal(err)
}

publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
log.Fatal("error casting public key to ECDSA")
}

fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)
nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
if err != nil {
log.Fatal(err)
}

value := big.NewInt(0) // in wei (0 eth)
gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
log.Fatal(err)
}

        // Адрес получателя
toAddress := common.HexToAddress("0xeFDB9E216F42424B54eB591AD086F20165830ad7")

        // Адрес контракта
tokenAddress := common.HexToAddress("0xBACeE245e9a6b1846d225d9D21B1F5E22C374741")

transferFnSignature := []byte("transfer(address,uint256)")
hash := sha3.NewKeccak256()
hash.Write(transferFnSignature)
methodID := hash.Sum(nil)[:4]
fmt.Println(hexutil.Encode(methodID)) // 0xa9059cbb

paddedAddress := common.LeftPadBytes(toAddress.Bytes(), 32)
fmt.Println(hexutil.Encode(paddedAddress))

amount := new(big.Int)
amount.SetString("1000000000000000000000", 10) // 1000 tokens
paddedAmount := common.LeftPadBytes(amount.Bytes(), 32)
fmt.Println(hexutil.Encode(paddedAmount))

var data []byte
data = append(data, methodID...)
data = append(data, paddedAddress...)
data = append(data, paddedAmount...)

gasLimit, err := client.EstimateGas(context.Background(), ethereum.CallMsg{
To:   &toAddress,
Data: data,
})
if err != nil {
log.Fatal(err)
}
fmt.Println(gasLimit)

tx := types.NewTransaction(nonce, tokenAddress, value, gasLimit, gasPrice, data)

chainID, err := client.NetworkID(context.Background())
if err != nil {
log.Fatal(err)
}

signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey)
if err != nil {
log.Fatal(err)
}

err = client.SendTransaction(context.Background(), signedTx)
if err != nil {
log.Fatal(err)
}

fmt.Printf("tx sent: %s", signedTx.Hash().Hex())
}


Эмуляция блокчейна выполнена на Ganache v1.2.2.

Меня беспокоит данный метод (Estimate Gas) лимит на газ выдает мне 0
Code:
	gasLimit, err := client.EstimateGas(context.Background(), ethereum.CallMsg{
To:   &toAddress,
Data: data,
})

Переменные:
privateKey - Приватный ключь
toAddress - Адрес получателя
tokenAddress - Адрес контракта
все данные были взяты с Ganache, но не пойму в чем проблема, Адрес контракта ввожу вверно https://prnt.sc/l8330e

Заранее благодарен за помощь.






sashakravchukk
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
October 20, 2018, 06:46:33 AM
 #2

У меня аналогичная проблема
expressphpcode (OP)
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile
October 20, 2018, 11:36:30 AM
 #3

Если присвоить переменной gasLimit, реальное значения (GAS LIMIT), то транзакция выполняется успешно.
Проблема скорее всего в эмуляторе Ganache v1.2.2

так как метод:
Code:
	gasLimit, err := client.EstimateGas(context.Background(), ethereum.CallMsg{
To:   &toAddress,
Data: data,
})
возвращяет 0, вместо положенного лимита который был внесен в контракт.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!