如何修复ethereumjs-tx的“未定义不是对象(评估'Transform.call')”

问题描述 投票:0回答:2

我想开发一个移动应用程序,它将发送交易以与我的智能合约进行交互。

执行“ ethereumjs-tx.sign(..)”时,将引发异常。(前言:我正在使用web3 @ 0.19,ethereumjs-util @ 4.4和[email protected]包含我的应用程序。)

我试图在ethereumjs-tx中执行其他功能,例如toCreationAddress()和getChainId()。他们是工作。另外,我尝试了最新版本的web3,ethereumjs-tx和ethereumjs-util,但没有帮助。

import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';

import './global';

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/'));
var util = require('ethereumjs-util');
var tx = require('ethereumjs-tx');

export default function App() {

  pressMe = () => {
    var rawTx = {
        nonce: '0x002D',
        gasPrice: '0x3B9ACA00',
        gasLimit: '0xC20A',
        to: <<..smart contract address..>>
        value: '0x00',
        data: '0x...',
        chainId:"0x03"
    }
    console.log(rawTx);
    var p = new Buffer(<<..privateKey..>>, 'hex');
    var transaction = new tx(rawTx);

    transaction.sign(p) ;

  }

  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <Button onPress={this.pressMe} title="Click"></Button>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

[当运行“ pressMe”函数并执行“ transaction.sign(p)”时,它将引发异常。

“错误捕获屏幕”“ >>

请帮助。

我想开发一个移动应用程序,它将发送交易以与我的智能合约进行交互。当执行“ ethereumjs-tx.sign(..)”时,它将引发异常。 (FYR:我正在使用[email protected],...

react-native private-key sign smartcontracts
2个回答
0
投票

我很确定RN中没有提供Buffer的实现。您需要添加一个作为依赖项:yarn add buffer


0
投票

您正在使用Buffer。它将被嵌入到React-native中。请导入Buffer

© www.soinside.com 2019 - 2024. All rights reserved.