jimmychu0807 / substrate-front-end-template

A Polkadot.js API + React based template for building Substrate Front Ends
The Unlicense
315 stars 352 forks source link

Latest Front End with the latest node-template extrinsic transactions not working #165

Closed ConnorBP closed 3 years ago

ConnorBP commented 3 years ago

I have a node based on the latest substrate-node-template and I am trying to get this working with it. On the node template the main thing I have changed is the ss58 address prefix.

I launched the template and noticed first of all that this does not seem to change the address prefix used based on the metadata sent out by the node like the apps gui does. However secondly, and more importantly, when I try to submit an extrinsic for the template-pallet I get the following vague error:

Unhandled Rejection (Error): createType(ExtrinsicV4):: Struct: failed on signature: Type:: Enum(Index):: AccountIndex: Input too large. Found input with 33 bits, expected 32

I have been trying to wrap my head around why this could possibly be happening. Why on earth is it sending 33 bits instead of 32? Is it using the wrong Account type? is it because of the ss58 prefix?

I have gone in and tried messing with the following in the types file: "Address": "MultiAddress", "LookupSource": "MultiAddress", "Signature": "MultiSignature", to no avail.

and I went into SubstrateContext.js to force it onto the correct address prefix:

const ss58Format = 0xCE;
keyring.setSS58Format(ss58Format);
///
// Loading accounts from dev and polkadot-js extension

let loadAccts = false;
const loadAccounts = (state, dispatch) => {
  const asyncLoadAccounts = async () => {
    dispatch({ type: 'LOAD_KEYRING' });
    try {
      await web3Enable(config.APP_NAME);
      let allAccounts = await web3Accounts();
      allAccounts = allAccounts.map(({ address, meta }) =>
        ({ address, meta: { ...meta, name: `${meta.name} (${meta.source})` } }));
      keyring.loadAll({ isDevelopment: config.DEVELOPMENT_KEYRING, ss58Format: ss58Format }, allAccounts);
      dispatch({ type: 'SET_KEYRING', payload: keyring });
    } catch (e) {
      console.error(e);
      dispatch({ type: 'KEYRING_ERROR' });
    }
  };

But still no dice.

If anyone knows why this is happening, I would love to know.

And in terms of issues to be fixed, if the current front end template and node-templates are not compatible that should be addressed. This could possibly be an issue with the substrate js-api itself though i'm not sure.

And additionally this really should be reading the meta data sent from the node as to what ss58 prefix to use just like on apps https://polkadot.js.org/docs/substrate/constants#ss58prefix-u8 https://github.com/polkadot-js/apps/pull/3879/files

jimmychu0807 commented 3 years ago

Thanks for reporting @ConnorBP. Will take a look in this issue.

nuke-web3 commented 3 years ago

checking in here - was there any resolution we can get for record here? 🙏🏼 If not, I can investigate further - just LMK

jimmychu0807 commented 3 years ago

let me check this today

jimmychu0807 commented 3 years ago

Hi @ConnorBP, may I see the code how you set the ss58 address format on the Substrate side? Could you make a branch in your repo and point me there?

The reason I ask is because I setup a 3-node polkadot network using kusama-dev chain spec instead of a regular Substrate dev node. The connected frontend template get the metadata as 0x02 the Kusama code (regular Substrate ss58 prefix is 42, or 0x2a). I can also do a balance transfer successfully.

Screenshot 2021-03-20 at 18 16 32

Commands I start my 3-node network:

target/debug/polkadot --tmp --chain "kusama-dev" --port 30333 --rpc-port 9933 --alice
target/debug/polkadot --tmp --chain "kusama-dev" --port 30334 --rpc-port 9934
target/debug/polkadot --tmp --chain "kusama-dev" --port 30335 --rpc-port 9935
ConnorBP commented 3 years ago

he code how you set the ss58 address format on the Substrate side? Could you make a branch in your repo and point me there?

Sorry, I was away for a while. I will see about getting that set up for you.

Here is a gist with (I believe) everything where the custom code was added including a modified crypto.rs from substrate/primitives/core/src/crypto.rs https://gist.github.com/ConnorBP/ce22e659f2f76ec7f7deea4f865a944e

#[cfg(feature = "full_crypto")]
ss58_address_format!(
    PolkadotAccount =>
        (0, "polkadot", "Polkadot Relay-chain, standard account (*25519).")
    BareSr25519 =>
        (1, "sr25519", "Bare 32-bit Schnorr/Ristretto 25519 (S/R 25519) key.")
    KusamaAccount =>
        (2, "kusama", "Kusama Relay-chain, standard account (*25519).")
    BareEd25519 =>
        (3, "ed25519", "Bare 32-bit Edwards Ed25519 key.")
    KatalChainAccount =>
        (4, "katalchain", "Katal Chain, standard account (*25519).")
    PlasmAccount =>
        (5, "plasm", "Plasm Network, standard account (*25519).")
    BifrostAccount =>
        (6, "bifrost", "Bifrost mainnet, direct checksum, standard account (*25519).")
    EdgewareAccount =>
        (7, "edgeware", "Edgeware mainnet, standard account (*25519).")
    KaruraAccount =>
        (8, "karura", "Acala Karura canary network, standard account (*25519).")
    ReynoldsAccount =>
        (9, "reynolds", "Laminar Reynolds canary network, standard account (*25519).")
    AcalaAccount =>
        (10, "acala", "Acala mainnet, standard account (*25519).")
    LaminarAccount =>
        (11, "laminar", "Laminar mainnet, standard account (*25519).")
    PolymathAccount =>
        (12, "polymath", "Polymath network, standard account (*25519).")
    SubstraTeeAccount =>
        (13, "substratee", "Any SubstraTEE off-chain network private account (*25519).")
    TotemAccount =>
        (14, "totem", "Any Totem Live Accounting network standard account (*25519).")
    SynesthesiaAccount =>
        (15, "synesthesia", "Synesthesia mainnet, standard account (*25519).")
    KulupuAccount =>
        (16, "kulupu", "Kulupu mainnet, standard account (*25519).")
    DarkAccount =>
        (17, "dark", "Dark mainnet, standard account (*25519).")
    DarwiniaAccount =>
        (18, "darwinia", "Darwinia Chain mainnet, standard account (*25519).")
    GeekAccount =>
        (19, "geek", "GeekCash mainnet, standard account (*25519).")
    StafiAccount =>
        (20, "stafi", "Stafi mainnet, standard account (*25519).")
    DockTestAccount =>
        (21, "dock-testnet", "Dock testnet, standard account (*25519).")
    DockMainAccount =>
        (22, "dock-mainnet", "Dock mainnet, standard account (*25519).")
    ShiftNrg =>
        (23, "shift", "ShiftNrg mainnet, standard account (*25519).")
    ZeroAccount =>
        (24, "zero", "ZERO mainnet, standard account (*25519).")
    AlphavilleAccount =>
        (25, "alphaville", "ZERO testnet, standard account (*25519).")
    JupiterAccount =>
        (26, "jupiter", "Jupiter testnet, standard account (*25519).")
    PatractAccount =>
        (27, "patract", "Patract mainnet, standard account (*25519).")
    SubsocialAccount =>
        (28, "subsocial", "Subsocial network, standard account (*25519).")
    DhiwayAccount =>
        (29, "cord", "Dhiway CORD network, standard account (*25519).")
    PhalaAccount =>
        (30, "phala", "Phala Network, standard account (*25519).")
    LitentryAccount =>
        (31, "litentry", "Litentry Network, standard account (*25519).")
    RobonomicsAccount =>
        (32, "robonomics", "Any Robonomics network standard account (*25519).")
    DataHighwayAccount =>
        (33, "datahighway", "DataHighway mainnet, standard account (*25519).")
    AresAccount =>
        (34, "ares", "Ares Protocol, standard account (*25519).")
    ValiuAccount =>
        (35, "vln", "Valiu Liquidity Network mainnet, standard account (*25519).")
    CentrifugeAccount =>
        (36, "centrifuge", "Centrifuge Chain mainnet, standard account (*25519).")
    NodleAccount =>
        (37, "nodle", "Nodle Chain mainnet, standard account (*25519).")
    KiltAccount =>
        (38, "kilt", "KILT Chain mainnet, standard account (*25519).")
    PolimecAccount =>
        (41, "poli", "Polimec Chain mainnet, standard account (*25519).")
    SubstrateAccount =>
        (42, "substrate", "Any Substrate network, standard account (*25519).")
    BareSecp256k1 =>
        (43, "secp256k1", "Bare ECDSA SECP256k1 key.")
    ChainXAccount =>
        (44, "chainx", "ChainX mainnet, standard account (*25519).")
    UniartsAccount =>
        (45, "uniarts", "UniArts Chain mainnet, standard account (*25519).")
    Reserved46 =>
        (46, "reserved46", "Reserved for future use (46).")
    Reserved47 =>
        (47, "reserved47", "Reserved for future use (47).")
    NeatcoinAccount =>
        (48, "neatcoin", "Neatcoin mainnet, standard account (*25519).")
    AventusAccount =>
        (65, "aventus", "Aventus Chain mainnet, standard account (*25519).")
    CrustAccount =>
        (66, "crust", "Crust Network, standard account (*25519).")
    CeruleanAccount =>
        (206, "cerulean", "Cerulean mainnet, standard account (*25519).")
    // Note: 16384 and above are reserved.
);

edit: forgot to post the url. https://gist.github.com/ConnorBP/ce22e659f2f76ec7f7deea4f865a944e

jimmychu0807 commented 3 years ago

This should work now. Let me know if you still have any issue. If yes, please reopen this. Thanks.