为了账号安全,请及时绑定邮箱和手机立即绑定

ERC-20 代币转移问题:执行恢复:ERC20:从零地址转移

ERC-20 代币转移问题:执行恢复:ERC20:从零地址转移

Go
慕容708150 2022-10-10 19:11:47
最近我一直在尝试学习有关智能合约的知识,但是当我试图了解代币转移的工作原理时,我遇到了这个问题。|| 执行恢复:ERC20:从零地址转移 || (罗普斯滕网络)编码: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 个代币的钱包,toAddress 是普通钱包。我在这里想念什么?
查看完整描述

1 回答

?
慕斯王

TA贡献1864条经验 获得超2个赞

显然,问题出在gasLimit. 我将其更改gasLimit为:

gasLimit := uint64(200000)

它奏效了。


查看完整回答
反对 回复 2022-10-10
  • 1 回答
  • 0 关注
  • 105 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号