我想开发一个移动应用程序,它将发送交易以与智能合约进行交互。
执行“ 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)”时,它将引发异常。
请帮助。
答案 0 :(得分:0)
我很确定RN中没有提供ITax
的实现。
您需要添加一个作为依赖项:
Buffer
..然后添加到您的导入中:
yarn add buffer
答案 1 :(得分:0)
您正在使用Buffer
。它将被嵌入到React-native中。请导入Buffer
。
var Buffer = require('buffer/').Buffer
var p = Buffer(<<..privateKey..>>, 'hex');