- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近一直在尝试学习有关智能合约的知识,但是当我试图了解代币转移的工作原理时,我遇到了这个问题。 ||执行恢复:ERC20:从零地址转账|| (ropsten 网络)
代码:
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))
paddedAddress := common.LeftPadBytes(toAddress.Bytes(),32)
fmt.Println(hexutil.Encode(paddedAddress))
amount := new(big.Int)
amount.SetString("10000000000000000000", 10)
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: &tokenAddress,
Data: data,
})
if err != nil {
log.Fatal(err)
}
gasPrice, err := client.SuggestGasPrice(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Println(gasLimit)
tx := types.NewTx(&types.LegacyTx{
Nonce: nonce,
GasPrice: gasPrice,
Gas: gasLimit,
To: &tokenAddress,
Value: value,
Data: data,
V: nil,
R: nil,
S: nil,
})
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("TOKEN TX SENT! || %s ||", signedTx.Hash().Hex())
}
token地址是我的合约地址,fromAddress是我的钱包,里面有我的10000个token,toAddress是一个普通的钱包。我在这里错过了什么?
最佳答案
显然,问题出在 gasLimit
上。我将 gasLimit
更改为:
gasLimit := uint64(200000)
它奏效了。
关于go - ERC-20代币转移问题: execution reverted: ERC20: transfer from the zero address,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69843470/
翻译: 用法:zeros(shape, dtype=float, order='C') 返回:返回来一个给定形状和类型的用0填充的数组; 参数:shape:形状 dtype:数据类型,可选参
我想像这样格式化一个 double: 1.23 => 1.2 1.0 => 1 0.4 => 0.4 0 => 0 对应的字符串格式是什么?我目前正在使用 StringFormat={}{0
在 simple geometric program 中用 Javascript 和 Canvas 编写,当我将 Angular 设置为 270° (1½π) 时,我预计 Math.cos(θ) 会变
我们有一些基于 Linux (Centos) 的虚拟机,它们将用作可分发的虚拟设备。我们希望能够尽可能地压缩它们以便分发(通过 tar.gz、zip 等)。 我们删除了所有不必要的文件(.log's、
之前有一个问题,它得到了答案: 感谢那。 “现在我已经格式化了我的单元格: h "小时"m "分钟" 因此,如果我的单元格有 7:00,它会显示为 7 小时 0 分钟。如果小时或分钟为零,有没有办法删
这个问题已经有答案了: C program to convert Fahrenheit to Celsius always prints zero (6 个回答) 已关闭 4 年前。 我的以下简单编码
我有一个类的以下代码。这是一个类的初始化。 第三方动态链接库 [DllImport("gdi32.dll")] public static extern IntPtr CreateCompatib
这是我书中的一段代码,我不确定匹配是如何工作的,因为它似乎第一个案例匹配所有内容。以下是 Ocaml 向我提出的警告: # let zero = 0;; # let one = 1;; # let r
我正在尝试重构一些现有代码into a more monodic approach 。现有代码包含接口(interface) IXInterface 和数字,例如 int 和 bool。默认情况下,数
我一直在考虑单词序列的 0 填充以及如何将 0 填充转换为嵌入层。乍一看,人们会认为您也希望保持嵌入 = 0.0。但是,keras 中的嵌入层会为任何输入标记生成随机值,并且无法强制其生成 0.0。请
我正在尝试使用 Pandas 解决以下 python 面试问题: 给定一个 m x n 矩阵,如果一个元素为 0,则将其整个行和列设置为 0。就地执行。 这里有一些例子: # Example 1 [[
我正在优化我正在编写的程序中最耗时的循环,该循环对数组中的许多条目求和,其中许多条目将为零。在添加之前检查条目是否为零或跳过检查并添加所有条目是否更快?下面每一个的例子。这是在 C++ 中。谢谢! d
之前(作为菜鸟)我将它作为 R 包错误提交,让我由你们来运行它。我认为以下所有内容都很好: replace_number("123 0 boogie") [1] "one hundred twenty
默认情况下,在BPI零M2上禁用eth0。。在这里,我们将演示如何启用它
我有一个 PG 数据库表价格。结构如下: id name total_sales created_at 1 A 0.0 2016-01-01
这个问题在这里已经有了答案: Difference between numpy.array shape (R, 1) and (R,) (8 个答案) 关闭 6 年前。 有什么区别 numpy.ze
是否可以通过 Skype 用户窗口获取处理程序并使用 SendMessage(whdl,BM_CLICK,intptr.zero,intrptr.zero,intptr.zero) 单击发送文件或调用
我使用开箱即用的 MVC 4 简单成员资格。我对网站做了很多修改,现在我要回去清理,我发现我不能再修改我的密码了。我一定是视而不见,因为我认为这应该很容易解决,但我只花了 2 天时间解决这个问题。 我
我是CorePlot的新手,终于搞定了一些散线图显示。如何将 X 轴设置为零并位于图形底部,将 Y 轴设置为零并位于图形左侧? 最佳答案 将 plotSpace 的 xRange 设置为 plotSp
我已经为数据表实现了 LazyLoading。当我使用分页浏览数据表时,出现以下异常。 com.sun.faces.context.PartialViewContextImpl processPart
我是一名优秀的程序员,十分优秀!