Ethereumjs

無法將字元串轉換為緩衝區。toBuffer 僅支持 0x 前綴的十六進製字元串

  • May 1, 2021

創建乙太坊原始交易時出錯

var rawTx = {
 nonce: '0x2a',
 gasPrice: '0x4a717c800',
 gasLimit: '0xc340',
 to: '0x73F7Ced8cc9D27DC426210c32fc6d0a40f941eE1',
 value: '0x2386f26fc10000',
 data: '',
 chainID: 4 
}      
var cTx = await new EthereumTx(rawTx, { 'chain': 'rinkeby' });
cTx.sign(privateKeyInBuffer);

嘗試將數據:‘‘更改為數據:“0x”

ethereum-utils 檢查字元串欄位是否為十六進制。當您將數據欄位發送為空時,它會引發錯誤。您可以像上面所說的那樣將數據發送為“0x”。

引用自:https://ethereum.stackexchange.com/questions/80205