This is necessary to substitute the TextEncoder/TextDecoder for use with nodejs. The Api must be extended and serializeTransaction and deserializeTransaction overwritten.
import { Api, SerialBuffer } from "eosjs2"
import { TextDecoder, TextEncoder } from "text-encoding"
export class MyEosjsApi extends Api {
public serializeTransaction(transaction: any): Uint8Array {
const textEncoder = new TextEncoder()
const textDecoder = new TextDecoder()
const buffer = new SerialBuffer({ textEncoder, textDecoder })
this.serialize(buffer, "transaction", {
max_net_usage_words: 0,
max_cpu_usage_ms: 0,
delay_sec: 0,
context_free_actions: [],
actions: [],
transaction_extensions: [],
...transaction,
})
return buffer.asUint8Array()
}
public deserializeTransaction(transaction: Uint8Array): any {
const textEncoder = new TextEncoder()
const textDecoder = new TextDecoder()
const buffer = new SerialBuffer({ textEncoder, textDecoder })
buffer.pushArray(transaction)
return this.deserialize(buffer, "transaction")
}
}
This is necessary to substitute the TextEncoder/TextDecoder for use with nodejs. The Api must be extended and
serializeTransaction
anddeserializeTransaction
overwritten.