首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有在Ropsten网络上传输Ethereum

没有在Ropsten网络上传输Ethereum
EN

Ethereum用户
提问于 2020-09-23 07:21:08
回答 1查看 159关注 0票数 0

下面是我在Ropsten testnet上签名和发送事务的代码,它正在正常工作。但是,设置为'1‘eth的值不会传输到目标地址。

代码语言:javascript
复制
var Tx = require('ethereumjs-tx').Transaction

const Web3 = require ('web3')
const web3 = new Web3('MY URL including the key')
 
//Public keys for two accounts
const account1 = '0x8dAd70D461d01C2945A0a1b358eDF21544E03d07'
const account2 = '0x2bA9D4119A2F5c80812d273F3720347dd529FD0A'

const prKey1 = Buffer.from(process.env.PR_KEY1.substring(2,66), 'hex')
const prKey2 = Buffer.from(process.env.PR_KEY2.substring(2,66), 'hex')



// *********************Transfer from account 1 to account 2 *******************
web3.eth.getTransactionCount(account1, (err, txCount) => {
// Build the transaction
    const txObject = {
    nonce: web3.utils.toHex(txCount),
    to: account2,
    Value: web3.utils.toHex(web3.utils.toWei('1', 'ether')), 
    gasLimit: web3.utils.toHex(21000), 
    gasPrice: web3.utils.toHex(web3.utils.toWei('100' , 'gwei')) 
    
    }


// Sign the transaction - choose ropsten as the network
    const tx = new Tx(txObject, {chain: 'ropsten'})
    tx.sign(prKey1)
    
    const serializedTransaction = tx.serialize()
    const raw = '0x' + serializedTransaction.toString('hex')

// Broadcast the transaction 
    web3.eth.sendSignedTransaction(raw, (err, txHash) => {
        console.log('txHash:', txHash)
  })
})
EN

回答 1

Ethereum用户

回答已采纳

发布于 2020-09-23 08:14:36

将object txObject中的参数D1更改为value (没有大写字母)。愚蠢的错误,但经常发生:)

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/87691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档