astarnetwork / api Goto Github PK
View Code? Open in Web Editor NEWAstar Network library for dApps and client applications
License: MIT License
Astar Network library for dApps and client applications
License: MIT License
Hi, using shiden network got error when I geting nonce from chain by system_accountNextIndex
:
{ code: -32601, message: 'Method not found' },
And this is a common api for polkadot,
https://polkadot.js.org/docs/substrate/rpc/#system
so I want to ask how can I reslove that? Any other JSON RPC api to get nonce?
this package and its dependencies are very outdated.
Please update the Plasm types, polkadot-js/api version, and remove redundant types that are included in the plasm api by default (e.g., ethereum types).
We also may need to split the type imports into main and Dusty rather than using a single interface folder.
I tried to use plasm-types libray to run a simple app for transferring tokens between Dusty accounts on plasm. Source code and package.json for running the snippet is found on this git repo
Node version: v12.8.2
Yarn version: 1.22.5
`require('dotenv').config();
const { ApiPromise, WsProvider } = require('@polkadot/api')
const { Keyring } = require('@polkadot/keyring')
const plasmDefinitions = require('@plasm/types/interfaces/definitions');
const jsonDefinitions = require('./types.js')
const fs = require('fs')
const BN = require('bn.js')
startChain()
async function startChain() {
console.log("trying connection to ", process.env.RPC_URL)
const targetAddress = process.env.TARGET_ADDRESS
const provider = new WsProvider(process.env.RPC_URL)
const types = Object.values(plasmDefinitions).reduce(
(res, { types }) => ({ ...res, ...types }),
{},
);
const api = new ApiPromise({
provider,
types
});
api.on('connected', () => console.log(Connected to ${process.env.RPC_URL}
));
api.on('disconnected', () => console.log(Disconnected from ${process.env.RPC_URL}
));
await api.isReady;
const [chain, nodeName, nodeVersion] = await Promise.all([
api.rpc.system.chain(),
api.rpc.system.name(),
api.rpc.system.version()
])
console.log(You are connected to chain ${chain} using ${nodeName} v${nodeVersion} - ${process.env.RPC_URL}
)
const keyring = new Keyring({ type: 'sr25519' })
const fromPair = keyring.addFromUri(process.env.PLASM_MNEMONIC)
const fromAmountUnits = new BN('1000000000000000')
const transfer = api.tx.balances.transfer(targetAddress, fromAmountUnits)
// send value
//const nonce = await api.query.system.accountNonce(process.env.FROM_ADDRESS)
const nonce = await api.rpc.system.accountNextIndex(process.env.FROM_ADDRESS)
console.log("got nonce", nonce)
const txHash = await transfer.signAndSend(fromPair, {nonce})
}`
Stack trace:
trying connection to wss://rpc.dusty.plasmnet.io/ Connected to wss://rpc.dusty.plasmnet.io/ You are connected to chain Dusty using Plasm Node v1.6.1-cf15b11-x86_64-linux-gnu - wss://rpc.dusty.plasmnet.io/ got nonce Type { negative: 0, words: [ 0 ], length: 1, red: null, registry: TypeRegistry {} } 2021-02-05 21:00:27 RPC-CORE: submitExtrinsic(extrinsic: Extrinsic): Hash:: 1002: Verification Error: Execution: Could not convert parameter
txbetween node and runtime: Error decoding field CheckMortality.0: RuntimeApi, Execution: Could not convert parameter
txbetween node and runtime: Error decoding field CheckMortality.0 (node:13572) UnhandledPromiseRejectionWarning: Error: 1002: Verification Error: Execution: Could not convert parameter
txbetween node and runtime: Error decoding field CheckMortality.0: RuntimeApi, Execution: Could not convert parameter
txbetween node and runtime: Error decoding field CheckMortality.0 at RpcCoder._checkError (<mydir>\examples\plasm-simple-transfer\node_modules\@polkadot\api\node_modules\@polkadot\rpc-provider\coder\index.js:84:13) at RpcCoder.decodeResponse (<mydir>\examples\plasm-simple-transfer\node_modules\@polkadot\api\node_modules\@polkadot\rpc-provider\coder\index.js:47:10) at WsProvider.value (<mydir>\examples\plasm-simple-transfer\node_modules\@polkadot\api\node_modules\@polkadot\rpc-provider\ws\index.js:214:90) at W3CWebSocket.value [as onmessage] (<mydir>\examples\plasm-simple-transfer\node_modules\@polkadot\api\node_modules\@polkadot\rpc-provider\ws\index.js:194:153) at W3CWebSocket._dispatchEvent [as dispatchEvent] (<mydir>\examples\plasm-simple-transfer\node_modules\yaeti\lib\EventTarget.js:107:17) at W3CWebSocket.onMessage (<mydir>\examples\plasm-simple-transfer\node_modules\websocket\lib\W3CWebSocket.js:234:14) at WebSocketConnection.<anonymous> (<mydir>\examples\plasm-simple-transfer\node_modules\websocket\lib\W3CWebSocket.js:205:19) at WebSocketConnection.emit (events.js:315:20) at WebSocketConnection.processFrame (<mydir>\examples\plasm-simple-transfer\node_modules\websocket\lib\WebSocketConnection.js:554:26) at <mydir>\examples\plasm-simple-transfer\node_modules\websocket\lib\WebSocketConnection.js:323:40 (node:13572) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:13572) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Additionally when i try to do a clear run (delete node_modules and reinstall) i get the same message but with field CheckMortality replaced by CheckNonce. Fields returned by plasm-types library can be found in this file in json format
Simply put, if I try to introduce '@plasm/types' via require, I will get an error.
index.js
require("@plasm/types")
excucte: node index.js
:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/...
require() of ES modules is not supported.
require() of /home/... is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.