> For the complete documentation index, see [llms.txt](https://docs.harmony.one/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.harmony.one/home/developers/api/sample-code.md).

# Sample Code

## Setting Up an Account

```javascript
const mnes = 'urge clog right example dish drill card maximum mix bachelor section select';
const password = 'some phrase';
const added_mnemonic = harmony.wallet.addByMnemonic(mnes, 0);
await harmony.wallet.encryptAccount(added_mnemonic.address, password);
```

## Creating a Transaction Object

```javascript
const txn_object = {
    nonce: id,
    gasPrice: new Unit(0).asWei().toWei(),
    gasLimit: new Unit(21000).asWei().toWei(),
    shardID: 0,
    to: getAddress('one129r9pj3sk0re76f7zs3qz92rggmdgjhtwge62k').checksum,
    value: new Unit('1000000000000000000').asWei().toWei(),
    data: '0x',
};
```

## hmy\_sendRawTransaction

```javascript
const txn = harmony.transactions.newTx(txn_object);
const signed = await harmony.wallet.signTransaction(txn, harmony.wallet.signer, password);
console.log(signed.getRawTransaction());
const [Transaction, hash] = await signed.sendTransaction();
const confirmed = await Transaction.confirm(hash);
console.log('Transaction Receipt', confirmed.receipt);
if (confirmed.isConfirmed()) {
  console.log('transaction did go through');
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.harmony.one/home/developers/api/sample-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
