-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(chain): add low/high level api examples
- Loading branch information
Showing
4 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { AeSdk, Node, MemoryAccount, encode, Encoding } from '@aeternity/aepp-sdk'; | ||
|
||
const aeSdk = new AeSdk({ | ||
nodes: [ | ||
{ | ||
name: 'testnet', | ||
instance: new Node('https://testnet.aeternity.io'), // host your node for better decentralization | ||
}, | ||
], | ||
accounts: [new MemoryAccount('sk_2CuofqWZHrABCrM7GY95YSQn8PyFvKQadnvFnpwhjUnDCFAWmf')], | ||
}); | ||
|
||
const transactionInfo = await aeSdk.spend( | ||
100, // aettos | ||
'ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E', | ||
{ payload: encode(Buffer.from('spend tx payload'), Encoding.Bytearray) }, | ||
); | ||
console.log(transactionInfo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Node, MemoryAccount, buildTxAsync, Tag, encode, Encoding } from '@aeternity/aepp-sdk'; | ||
|
||
const onNode = new Node('https://testnet.aeternity.io'); // host your node for better decentralization | ||
const account = new MemoryAccount('sk_2CuofqWZHrABCrM7GY95YSQn8PyFvKQadnvFnpwhjUnDCFAWmf'); | ||
|
||
const spendTx = await buildTxAsync({ | ||
tag: Tag.SpendTx, | ||
senderId: account.address, | ||
recipientId: 'ak_21A27UVVt3hDkBE5J7rhhqnH5YNb4Y1dqo4PnSybrH85pnWo7E', | ||
amount: 100, // aettos | ||
payload: encode(Buffer.from('spend tx payload'), Encoding.Bytearray), | ||
onNode, | ||
}); | ||
|
||
const signedTx = await account.signTransaction(spendTx, { networkId: await onNode.getNetworkId() }); | ||
|
||
// broadcast the signed tx to the node | ||
const { txHash } = await onNode.postTransaction({ tx: signedTx }); | ||
console.log(txHash); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters