Setting the default user account

Before our trader can submit orders to the network, they need to have a valid Stellar account, funded with the trading assets. We created the trader's accounts using the nodejs utility in the previous section.

To load the user's account and balances and submit orders from their account, we need to map the user's secret key to the app. This secret key is kept on the client side in the ephemeral storage, and is not sent to the server side.

The AppLogin.js component renders a single field called secret key, to capture the user's secret key.

The setAccount() method is called to map this secret key and the public key to the app state, like this:

setAccount = () => {

var account =
StellarSdk.Keypair.fromSecret(this.state.fields.secretkey).publicKey()

this.setState({
account
});
this.setBalance(account);
this.setOrderbook();
this.setTrades();
};

The public key is derived using the Keypair class in the StellarSdk. We set the account to the app state.

Within this method, we also call the setBalance method to set the account balance, the setOrderbook method to set event streams for each asset pair orderbookand the setTrades method to set up an event stream in order to receive trades whenever a new trade takes place. Let's take a look at these methods.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.78.106