Release Note
Release Note v6.0.0-beta.4
Replace ethers@v5/abi
with abiCoder of ethers@v6
As ethers@v6
provides a deep
argument to Result.toArray
method, we can upgrade our abiCoder module. And that brings some changes. ethers@v6
has dropped the use of bn.js, and replaced it with BigInt. So all the returned numbers will be in BigInt type, not a wrapper of bn.js. And the error message changed too. There are several situations you may find:
- passing a argument which is not a valid
BytesLike
value toutils.abi.decodeParams
, the error message changed frominvalid arrayify value
to a text starts withinvalid BytesLike value
. - passing the wrong argument to
utils.abi.decodeParams
, it won't throw errors but returns aResult
containing error objects. Maybe part of the data can be decoded correctly. - The number returned by abiCoder changed from a wrapper of bn.js to BigInt, so we recommend you not using apis of bn.js directly but wraping it with
BigNumber.js
(note thisBigNumber.js
is not the wrapper name ofether@v5/BigNumber
). If you don't want to useBigNumber.js
, you can use BigInt like normal number directly.
Change headers type in TronWeb constructor
Options of TronWeb constructor contains a headers field, and it used to be AxiosRequestHeaders
type. It's not a correct type because you can't set custom headers in it. Thus, we change it to HeadersType
which is equal to RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>
to make it work with custom headers. But there's a case what you may need to note is that when you want to retrive the values of the headers, you need to specify the type explicitly. Like below:
import { Types } from 'tronweb';
const apiKey = (tronWeb.fullNode.headers as Types.RequestHeaders)['TRON-PRO-API-KEY'];
Export all Types and enum objects
In the former versions of v6.0.0-beta, we didn't export types and enum objects. That causes several problems with using types with TronWeb. In this version, we export all types and enum objects to Types field, so you can use it like the headers retriving case before and below:
import { Types } from 'tronweb';
switch (contractType) {
case Types.ContractType.TransferContract:
// do something....
//...
}
Release Note v6.0.0-beta.3
New Features
- Add
Trx.ecRecover
to recover the address of a signed transaction. - Support both base58 format and hex format address field in keys of
updateAccountPermissions
params.
Better typescript type support
- Don't need to use any type for contract instance to call contract methods.
- When using plugins, you can define a new TronWeb type as below to support type for plugin props or methods:
declare namespace globalThis {
interface MyTronWeb extends TronWeb {
trx: {
getCurrentBlock(): Promise<Block & { fromPlugin: true }>;
getLatestBlock(): Promise<Block & { fromPlugin: true }>;
getSomeParameter(): string;
} & Trx;
}
}
const tronWeb = new TronWeb() as globalThis.MyTronWeb;
const someParameter = 'someParameter';
const result = tronWeb.plugin.register(MyPlugin, {
someParameter,
});
const result2 = await tronWeb.trx.getCurrentBlock();
assert.isTrue(result2.fromPlugin);
assert.equal(result2.blockID.length, 64);
const result3 = await tronWeb.trx.getSomeParameter();
assert.equal(result3, someParameter);
FAQ
- Cannot destructure property 'Transaction' of 'globalThis.TronWebProto' as it is undefined.
This is a problem caused by webpack as it doesn't load cjs file correctly. To solve this problem, you need to add a new rule like below:
{
test: /\.cjs$/,
type: 'javascript/auto'
}