- Support conflux-rust v2.4.0, mainly about 1559 upgrade
- Add three debug RPC method in
cfxnamespacedebug_getTransactionsByBlock,debug_getEpochReceiptProofByTransaction,debug_getTransactionsByEpoch - Add filter related RPC method in cfx namespace
cfx_newFilter,cfx_newBlockFilter,cfx_newPendingTransactionFilter,cfx_getFilterChanges,cfx_getFilterLogs,cfx_uninstallFilter - Add
pos_getAccountByPowAddress,pos_getConsensusBlocks,pos_getEpochState,pos_getLedgerInfoByEpoch,pos_getLedgerInfoByBlockNumber,pos_getLedgerInfoByEpochAndRound,pos_getLedgerInfosByEpochinposnamespace - Add trace method
trace_epochintracenamespace - Support new scheme for epoch parameter like EIP-1898, check details here, supported methods are:
cfx_getBalance,cfx_getCode,cfx_call,cfx_getNextNonce,cfx_getStorageAt
- Add
cfx_getCollateralInfoRPC method which was import fromconflux-rust v2.3.0 SponsorInfoadd two more fieldsavailableStoragePointandusedStoragePoint
- Optimize the gas and storageCollateral logic of transaction population.
- Add support the new InternalContract
ParamsControl - Remove
cfx_getLogsfilter's fieldoffsetandlimit - Add support for new RPC
cfx_getParamsFromVote - Update typescript datatype definitions
- Add more jsdoc comment to generate ts
d.tsfiles - Move
cfxrelated formatters (block, transaction, receipt, log and etc) to independent file./src/rpc/types/formmatter.js.
- Fix logFilter formater bug
- Fix contract method batch call bug
- Change trace
epochNumber,transactionPositionfrom BigInt to Int - Add field
totalEspaceTokensingetSupplyInfo's response
- Add support for PoS RPC methods
- Split RPC methods to it's own namespace, currently include:
cfx,pos,trace,txpool - Add support for batch RPC
- Browser export class name change from Conflux to
TreeGraph - Add method
getNextUsableNoncetoconflux.advanced, which will first try to usetxpool_nextNonceto get a usable nonce, if failed it will fall back tocfx_getNextNonce - Add three internal contracts
CrossSpaceCall,ConfluxContext,PoSRegister - Add one method
cfxMappedEVMSpaceAddresstoaddressutility.
- Add a new boolean field
validto indicate whether this trace has change state - The
internal_transfer_actiontype trace has added four new fieldfromPocket,toPocket,fromSpace,toSpace - The
callandcreatetype trace has added one new fieldspace
For detail explanation of the trace updates check this doc.
Check v2.0 changes for change details
- Add
provider.requestto make provider compliant with EIP-1193 - Add a new provider
WechatProviderwhich can be used in Wechat environment
Here is the complete Conflux-rust v2.0 RPC change overview
- Add
balancekey in the result ofestimateGasAndCollateralAdvanceas the balance ofoptions.from.
- Add method
checkBalanceAgainstTransaction, andestimateGasAndCollateralAdvanceto better estimate gas and check balance.
- Add
blockNumberto block related methodscfx_getBlockByHash,cfx_getBlockByEpochNumber,cfx_getBlockByHashWithPivotAssumptionwhich needConflux-rust v1.1.5or above. - Add one new RPC method
cfx_getBlockByBlockNubmer
format.bytesnow only support hex string, will not accept non hex utf-8 string- Add cli
cfxjswhich can random generate a0x1 prefix ethereumaddress Confluxadd a new methodgetEpochReceiptsByPivotBlockHash
- Support
keepAliveoption inConfluxinitialization. - Add one util method
tracesInTreeto return a tree structure traces. - Fix contract method override bug.
- Add a address utility method
shortenCfxAddress.
- Support
retryoption inConfluxinitialization. - Add pending transaction status enum
CONST.PENDING_TX_STATUScurrently have two value:FUTURE_NONCENOT_ENOUGH_CASH
- Optimize the address convert performance.
Confluxadd methodgetAccountPendingTransactionsto get one account's pending transaction.- Split API documents into several files, which is easy to read.
This version is corresponding to conflux-rust v1.1.3, check it's changelog for detailed info.
format.addresswill respectnetworkId,verboseflag even if the first parameter is an CIP37 address.- Add support for a standard token contract through
Conflux.CRC20 cfx_getLogsfilter option add one more fieldoffset- Add one RPC method
cfx_getAccountPendingInfoto get account's transaction pending info epochspubsub now accept one parametersubscription_epochthe supported values arelatest_mined(default) andlatest_state- Include
blockHash,epochHash,epochNumber,transactionHash, andtransactionPositionfor trace RPCs - When ABI encoding
bytes-Ntype, if the data's length is not enough, will auto pad (right) toN
getStatusmethod rethurn three new fieldslatestState,latestConfirmed,latestCheckpoint- add two
tracerelated rpctraceTransaction,traceFilter - add one debug rpc
getEpochReceipts - add two provider wrapper
wrapEthereum,wrapConfluxto work with metamask
Notice: this is an update corresponding conflux-rust v1.1.2
Conflux's option can passnetworkIdnow, and add a new methodupdateNetworkIdto sync networkId from RPC.format.addresswill return new CIP37 addresses, if you pass a hex address,networkIdshould also be passed as second parameter- add new method
format.hexAddressto format hex address - Wallet's constructor add a parameter
networkId - PrivateKeyAccount
constructor,decrypt,randomneed one more parameternetworkId Transaction,Messagesignmethod need one more parameternetworkId- Conflux's get methods will return new address, and same to contract method returned address.
getSupplyInforesponse add new fieldtotalCirculatinggetStatusresponse add new fieldnetworkId
- Add RPC method
traceBlocktoConfluxwhich can used to get block's execution trace
- export
Contract
// nodejs
const { Contract } = require('js-conflux-sdk');import { Contract } from 'js-conflux-sdk'- add
stateMutabilityfor method from abi
console.log(contract.symbol.stateMutability) // "view"
console.log(contract.transfer.stateMutability) // "nonpayable"- rename EventLog.params to EventLog.arguments
await conflux.contract.Transfer(null, null, null).getLogs({
fromEpoch: 2868400,
toEpoch: 2868500,
});
/* [
{
data: '0x0000000000000000000000000000000000000000000000000001184b321b4e44',
topics: [ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0x0000000000000000000000001dc05200485776b79f195a1e617dbccb6826f1c4', '0x000000000000000000000000882c4ddb1d3210b5ae778360729c04cd3242df70' ],
...,
arguments: NamedTuple(from,to,value)(3) [ '0x1dc05200485776b79f195a1e617dbccb6826f1c4', '0x882c4ddb1d3210b5ae778360729c04cd3242df70', 308186218974788n ]
}
] */- add
subscribeLogsfor EventLog
subscription = await contract.Transfer(null, null, null).subscribeLogs();
subscription.on('data', data => { console.log(data); });- contract decode constructor data with out bytecode
- add
conflux.getSupplyInfo
- WebsocketProvider with Websocket options
new Conflux({ url: 'ws://127.0.0.1', clientConfig: { maxReceivedFrameSize: 10_1000_1000 } }) // 10 MB- add
conflux.getVoteList - add
conflux.getDepositList - update
conflux.getTransactionReceipt
fix: update request id avoid repeat
// old
conflux.provider.requestId(); // "16055917399420726"
// new
conflux.provider.requestId(); // "175d4b91862001f4f81eb443"fix: use native websocket for front-end
- use BigInt for nodejs, JSBI for browser
// for nodejs
// old
conflux.getBalance(ADDRESS); // JSBI(1) [ -1153374696, sign: false ]
// new
conflux.getBalance(ADDRESS); // 3141592600nfix: EventCoder, FunctionCoder, valueCoder decode return string but not JSBI
- add
defaultGasRatioanddefaultStorageRatio
conflux = new Conflux({ defaultGasRatio: 1.1, defaultStorageRatio: 1.1, ... })- add
BaseAccountandPrivateKeyAccount
Account signTransaction and signMessage to be async
- add wallet
wallet use for create and manage Account by address
account = conflux.wallet.addRandom();
console.log(conflux.wallet.has(account.address));
// true
account = conflux.wallet.addPrivateKey(PRIVATE_KEY);
console.log(conflux.wallet.has(account.address));
// true
account = conflux.wallet.addKeystore(keystore, password);
console.log(conflux.wallet.has(account.address));
// truewallet use for sendTransaction
// old
account = conflux.Account(PRIVATE_KEY);
conflux.sendTransaction({ from: account.address, ...}) // address will call `cfx_sendTranscion`
conflux.sendTransaction({ from: account, ... }) // must be instance of `Account` to sign by sdk and call `cfx_sendRawTransaction`
// new
conflux.sendTransaction({ from: address, ... }) // if address not in `conflux.wallet`, call `cfx_sendTranscion`
account = conflux.wallet.addPrivate(PRIVATE_KEY);
conflux.sendTransaction({ from: account.address, ... }) // if account in `conflux.wallet`, sign by account and call `cfx_sendRawTransaction`
conflux.sendTransaction({ from: account, ... }) // same as `from: account.address`, but some user think input account instance with privateKey is unsafe- add Subscription
await conflux.subscribe(name, ...args); // => id
await conflux.subscribeEpochs(); // => Subscription with event 'data'
await conflux.subscribeNewHeads(); // => Subscription with event 'data'
await conflux.subscribeLogs(); // => Subscription with event 'data', 'revert'
await conflux.unsubscribe(id); // => boolean
await conflux.unsubscribe(subscription); // => boolean- add internal contract
contract = conflux.InternalContract('AdminControl');
console.log(contract);
contract = conflux.InternalContract('SponsorWhitelistControl');
console.log(contract);
contract = conflux.InternalContract('Staking');
console.log(contract);- add checksum address
// old
conflux.getBalance('0x1B716c51381e76900EBAA7999A488511A4E1fD0a'); // ok
conflux.getBalance('0x1B716c51381e76900EBAA7999A488511A4E1fD0A'); // ok
// new
conflux.getBalance('0x1B716c51381e76900EBAA7999A488511A4E1fD0a'); // ok
conflux.getBalance('0x1B716c51381e76900EBAA7999A488511A4E1fD0A'); // Error\('address checksum error'\)providerFactoryonly accept first argument as override options
// old
provider = providerFactory('http://localhost:12537')
// new
provider = providerFactory({ url: 'http://localhost:12537' })- add batch request
provider = providerFactory({ url: 'http://localhost:12537' })
array = await provider.batch([ { method: 'cfx_epochNumber' }, { method: 'cfx_getBalance', params: ['0x0123456789012345678901234567890123456789'] }])
// [ '0x1381', '0x0']- add WebSocketProvider
provider = providerFactory({ url: 'ws://localhost:12535' })
provider.close(); // user need to close before process ternimal- BaseProvider instanceof EventEmitter
const EventEmitter = require('events');
// old
console.log(new BaseProvider() instanceof EventEmitter); // false
console.log(new HttpProvider() instanceof EventEmitter); // false
// new
console.log(new BaseProvider({}) instanceof EventEmitter); // true
console.log(new HttpProvider({}) instanceof EventEmitter); // true
console.log(new WebSocketProvider({}) instanceof EventEmitter); // true- add CONST
const { CONST } = require('js-conflux-sdk');
console.log(CONST.EPOCH_NUMBER)
{
LATEST_MINED: 'latest_mined',
LATEST_STATE: 'latest_state',
LATEST_CONFIRMED: 'latest_confirmed',
LATEST_CHECKPOINT: 'latest_checkpoint',
EARLIEST: 'earliest'
}- export
formatandsignwithoututil
// old
const { util: {format, sign} } = require('js-conflux-sdk');
// new
const { format, sign } = require('js-conflux-sdk');- add
Dripto replace unit
// old
const { util } = require('js-conflux-sdk');
const balance = await conflux.getBalance(ADDRESS);
console.log(util.unit.fromDripToCFX(balance))
// new
const { Drip } = require('js-conflux-sdk');
const balance = await conflux.getBalance(ADDRESS);
console.log(Drip(balance).toCFX())for input, use Drip.fromXXX to get drip number string
// old
const { util } = require('js-conflux-sdk');
const tx = { to: ADDRESS, value: util.unit.fromCFXToDrip(0.1), ... }
// new
const { Drip } = require('js-conflux-sdk');
const tx = { to: ADDRESS, value: Drip.fromCFX(0.1), ... }- include all method from conflux JSON_RPC document
- friendly example code
example will guide user to use SDK step by step
- charming code organization
split abi coder with types
split contract method, event and override
- rename
send_transactiontocfx_sendTransaction
- Account.encrypt returned address drop '0x' prefix
- use scrypt-js
-
RPC returned all number as hex
-
fix
sendTransaction,call,estimateGasAndCollateralshallow copyoptions
Account.decryptrequired keystoreV3 object as input, and putpasswordas second parameter
// old
Account.decrypt('password', {salt:..., iv:..., cipher:..., mac:...})
// new
Account.decrypt({
version: 3,
id: '0bb47ee0-aac3-a006-2717-03877afa15f0',
address: '0x1cad0b19bb29d4674531d6f115237e16afce377c',
crypto: {
ciphertext: 'a8ec41d2440311ce897bacb6f7942f3235113fa17c4ae6732e032336038a8f73',
cipherparams: { iv: '85b5e092c1c32129e3d27df8c581514d' },
cipher: 'aes-128-ctr',
kdf: 'scrypt',
kdfparams: { dklen: 32, salt: 'b662f09bdf6751ac599219732609dceac430bc0629a7906eaa1451555f051ebc', n: 8192, r: 8, p: 1 },
mac: 'cc89df7ef6c27d284526a65cabf8e5042cdf1ec1aa4ee36dcf65b965fa34843d'
}
},
'password')Account.prototype.encryptreturned keystoreV3 format object
const account = new Account('0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef');
// old
account.encrypt('password')
/*
{
algorithm: 'aes-128-ctr',
N: 8192,
r: 8,
p: 1,
dkLen: 32,
salt: '0xb662f09bdf6751ac599219732609dceac430bc0629a7906eaa1451555f051ebc',
iv: '0x85b5e092c1c32129e3d27df8c581514d',
cipher: '0xa8ec41d2440311ce897bacb6f7942f3235113fa17c4ae6732e032336038a8f73',
mac: '0xcc89df7ef6c27d284526a65cabf8e5042cdf1ec1aa4ee36dcf65b965fa34843d'
}
*/
// new
account.encrypt('password')
/*
{
version: 3,
id: '0bb47ee0-aac3-a006-2717-03877afa15f0',
address: '0x1cad0b19bb29d4674531d6f115237e16afce377c',
crypto: {
ciphertext: 'a8ec41d2440311ce897bacb6f7942f3235113fa17c4ae6732e032336038a8f73',
cipherparams: {
iv: '85b5e092c1c32129e3d27df8c581514d'
},
cipher: 'aes-128-ctr',
kdf: 'scrypt',
kdfparams: {
dklen: 32,
salt: 'b662f09bdf6751ac599219732609dceac430bc0629a7906eaa1451555f051ebc',
n: 8192,
r: 8,
pw: 1
},
mac: 'cc89df7ef6c27d284526a65cabf8e5042cdf1ec1aa4ee36dcf65b965fa34843d'
}
}
*/- epochNumber accept
earliest,latest_checkpoint,latest_confirmedlabel
- add
getAdmin
await cfx.getAdmin('0x89996a8aefb2228593aae723d47f9517eef1341d') // "0x1be45681ac6c53d5a40475f7526bac1fe7590fb8"- sendTransaction accept privateKey as
from
cfx.sendTransaction({
from: PRIVATE_KEY, // accept Account instance or privateKey
to: ADDRESS, // accept Account instance or address
...,
})- create Account accept address
new Account(PRIVATE_KEY); // {privateKey:'0x...', publicKey: '0x...', address: '0x...'}
new Account(PUBLIC_KEY); // {publicKey: '0x...', address: '0x...'}
new Account(ADDRESS); // {address: '0x...'}- defaultGasPrice, only use for sendTransaction
cfx = new Conflux({ url: 'https://test.confluxrpc.com', defaultGasPrice: 100, });
// old
cfx.call({ address: '0x...', data: '0x...', }); // => cfx_call{defaultGasPrice:'0x64',address:'0x...',data:'0x...'}
// new
cfx.call({ address: '0x...', data: '0x...', }); // => cfx_call{address:'0x...',data:'0x...'}- remove defaultEpoch, defaultChainId, defaultGas, defaultStorageLimit
// old
cfx = new Conflux({ url: 'https://test.confluxrpc.com', defaultEpoch: 'latest_state', defaultChainId: 1, defaultGasPrice: 100, defaultGas: 10, defaultStorageLimit: 1, })
// new
cfx = new Conflux({ url: 'https://test.confluxrpc.com', defaultGasPrice: 100, })
// user could `epochNumber` and `chainId` manual on each method.- fix broken sourcemap
- fix: include crypto into browserify build
// old
ConfluxJSSDK.util.sign.randomPrivateKey() // TypeError randomBytes is not a function- add format.bytes
format.bytes('abcd'); // format.bytes([0, 1, 2, 3]);- add contract method & event type or signature indexes
// solidity function override(bytes memory str) public function override(string memory str) public
contract.override('str'); // Error: can not determine override
contract['override(string)']('str'); // specify override method by type contract['0x227ffd52']('str'); // specify override method by signature- add
getStatus
cfx.getStatus()- remove
getRiskCoefficientand replace withgetConfirmationRiskByHash
// old
cfx.getRiskCoefficient(epochNumber)
// new
cfx.getConfirmationRiskByHash(blockHash)- remove
getAccountcause it's internal RPC. - use
requirereplaceimportto gen code.
- add defaultStorageLimit and defaultChainId for Conflux
// old
const cfx = new Conflux({ url: 'https://test.confluxrpc.com', defaultGasPrice: 100, defaultGas: 100000, })
// new
const cfx = new Conflux({ url: 'https://test.confluxrpc.com', defaultGasPrice: 100, defaultGas: 100000, defaultStorageLimit: 4096, defaultChainId: 0, })- abi implicitly converting string to number
solidity method: function add(uint,uint) public returns (uint);
// old
await contract.add(1, '2'); // error! can not accept string
// new version
await contract.add(1, '2'); // good, converting string to number- format nonce as JSBI.BigInt
nonce = await cfx.getNextNonce(...)
// old 100000
// new JSBI.BigInt(100000)- format transaction fields
tx = await cfx.getTransactionByHash(txHash)
// old
{ storageLimit: "0x64", chainId: "0x0", epochHeight: "0x400", ... }
// new
{
storageLimit: JSBI.BigInt(100), // JSBI
chainId: 0,
epochHeight: 1024, ...
}- unit return string
// old
unit.fromCFXToGDrip(123) => JSBI.BigInt(123000000000)
unit.fromCFXToGDrip('0.1234567891') => Error('Cannot convert JSBI.BigInt')
// new
unit.fromCFXToGDrip(123) => "123000000000"
unit.fromCFXToGDrip('0.1234567891') => "123456789.1"- contract fields "code" rename to "bytecode"
// old
cfx.Contract({code, abi, address})
// new
cfx.Contract({bytecode, abi, address})- abi decodeData and decodeLog return object
result = contract.abi.decodeData('0x....')
// old
["Tom", JSBI.BigInt(18)]
// new
{ name: 'func' fullName: 'func(string name, uint age)', type: 'func(string,uint)', signature: '0x812600df', array: ["Tom", JSBI.BigInt(18)], object: { name: "Tom", age: JSBI.BigInt(18), } }