我想开发一个移动应用程序,将发送交易与我的智能合同互动。
当执行"ethereumjs-tx.sign(..)“时,抛出异常。(仅供参考:我使用web3@0.19,ethereumjs-util@4.4和ethereumjs-tx@1.3包括我的应用程序。)
我尝试执行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)”时,抛出异常。

请帮帮忙。
发布于 2019-11-26 07:40:00
我非常确定RN中没有提供Buffer的实现。
您需要添加一个作为依赖项:
yarn add buffer
..and然后,添加到您的导入:
import { Buffer } from 'buffer';
发布于 2019-11-26 09:55:21
您正在使用Buffer。它将嵌入到React-native中。请导入Buffer。
var Buffer = require('buffer/').Buffer
var p = Buffer(<<..privateKey..>>, 'hex');https://stackoverflow.com/questions/57490675
复制相似问题