

web3.js调用合约方法 send 报错 Returned error: unknown account | 登链社区 | 技术...
source link: https://learnblockchain.cn/question/2836
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

web3.js调用合约方法 send 报错 Returned error: unknown account
10 web3.js调用合约方法 send 报错 Returned error: unknown account
合约代码
调用合约方法代码
web3.js版本 ^1.6.1
第一个retreive 可以正常调用
第二个store报错
完整报错信息 Error: Returned error: unknown account
看到有回答是需要签名 查询了文档 没有查询到调用合约方法如何签名
其它 2 个回答
记一下后续把 也算是踩的最深的坑了
ethereumjs-tx ^2.1.2
node v14.14.0
web3 ^1.6.1
进行到签名这步的时候 一直报错invalid sender
我就觉得我签名肯定是没问题的 是链的问题
所以我就将我签名好的数据放到https://testnet.bscscan.com/pushTx上面去广播 发现还是会报错 所以我就怀疑是我签名错误的问题
查了很多资料发现是 我这是需要设置链的(我自己是这样认为的)
设置链的代码为
var Common = require('ethereumjs-common').default;
var BSC_FORK = Common.forCustomChain(
'mainnet',
{
name: 'Smart Chain - Testnet',
networkId: 97,
chainId: 97,
url: 'https://data-seed-prebsc-1-s1.binance.org:8545/'
},
'istanbul',
);
var tx = new Tx(rawTx, { 'common': BSC_FORK })
后面又遇到两个报错 一个是
Returned error: transaction underpriced
我的代码一开始没有设置gasPrice 和 gas 我看文档说是会自己填...
然后我就填上了gasPrice 没有填gas 按了个5 闭着眼睛按0(真希望我银行卡余额能这样改)
然后继续报错"Unhandled rejection Error: Returned error: intrinsic gas too low"
然后继续baidu stackoverflow找问题 最后gas设为50000 gasPrice为
web3.utils.toWei('300', 'gwei')
最后成功发起了store方法
终于踩完坑了 开心 感谢熊大佬
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK