最近我一直在嘗試學(xué)習(xí)有關(guān)智能合約的知識(shí),但是當(dāng)我試圖了解代幣轉(zhuǎn)移的工作原理時(shí),我遇到了這個(gè)問題。|| 執(zhí)行恢復(fù):ERC20:從零地址轉(zhuǎn)移 || (羅普斯滕網(wǎng)絡(luò))編碼:import ( "context" "crypto/ecdsa" "fmt" "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/ethclient" "golang.org/x/crypto/sha3" "log" "math/big")func main() { client, err := ethclient.Dial("https://ropsten.infura.io/v3") if err != nil { panic(err) } chainID, _ := client.NetworkID(context.Background()) privateKey, err := crypto.HexToECDSA("280a5fb7d2eef8c7956f4e6754c82a46f30496e43f50be4c8a457ef4e45fb1f4") 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) nonce, err := client.PendingNonceAt(context.Background(), fromAddress) if err != nil { log.Fatal(err) } value := big.NewInt(0) toAddress := common.HexToAddress("0x0cFd37C2A1c9d0B8833fFE5a772003a350B5Be3f") tokenAddress := common.HexToAddress("0x4f1c3F4D89826f27204769Af1617540c219E3A62") transferFnSignature := []byte("transfer(address,uint256)") hash := sha3.NewLegacyKeccak256() hash.Write(transferFnSignature) methodID := hash.Sum(nil)[:4] fmt.Println(hexutil.Encode(methodID))}代幣地址是我的合約地址,fromAddress 是我持有 10000 個(gè)代幣的錢包,toAddress 是普通錢包。我在這里想念什么?
1 回答

慕斯王
TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊
顯然,問題出在gasLimit
. 我將其更改gasLimit
為:
gasLimit := uint64(200000)
它奏效了。
- 1 回答
- 0 關(guān)注
- 102 瀏覽
添加回答
舉報(bào)
0/150
提交
取消