docs: update examples for making casts and writing data (#834)

This commit is contained in:
Satyajeet Pal
2023-04-12 09:25:01 -04:00
committed by GitHub
parent 3be37fe8c0
commit f89fe7f982
2 changed files with 19 additions and 3 deletions

View File

@@ -7,16 +7,20 @@ import * as ed from '@noble/ed25519';
const HUB_URL = process.env['HUB_ADDR'] || ''; // URL of the Hub
// If the Hub requests authentication, set the following constants
// const HUB_USERNAME = process.env['HUB_USERNAME'] || '';
// const HUB_PASSWORD = process.env['HUB_PASSWORD'] || '';
(async () => {
/**
* This should be set to the private key of a known signer for the user, instead of randomly generating
* one, or the Hubs will reject the message. See the make-data tutorial for examples of how to do this.
* one, or the Hubs will reject the message. See the write-data tutorial for examples of how to do this.
*/
const privateKey = ed.utils.randomPrivateKey();
const ed25519Signer = new NobleEd25519Signer(privateKey);
const dataOptions = {
fid: 1,
fid: 1, // Set to your fid.
network: FarcasterNetwork.DEVNET,
};
@@ -151,5 +155,9 @@ const HUB_URL = process.env['HUB_ADDR'] || ''; // URL of the Hub
castResults.map((castAddResult) => castAddResult.map((castAdd) => client.submitMessage(castAdd)));
// If your Hub requires authentication, use the following instead:
// const authMetadata = getAuthMetadata(HUB_USERNAME, HUB_PASSWORD);
// castResults.map((castAddResult) => castAddResult.map((castAdd) => client.submitMessage(castAdd, authMetadata)));
client.close();
})();

View File

@@ -16,7 +16,11 @@ import { Wallet } from 'ethers';
* Populate the following constants with your own values
*/
const HUB_URL = process.env['HUB_ADDR'] || ''; // URL of the Hub
const HUB_URL = process.env['HUB_ADDR'] || ''; // URL of the Hub - make sure to include port 2283
// If the Hub requests authentication, set the following constants
// const HUB_USERNAME = process.env['HUB_USERNAME'] || '';
// const HUB_PASSWORD = process.env['HUB_PASSWORD'] || '';
(async () => {
/**
@@ -59,6 +63,10 @@ const HUB_URL = process.env['HUB_ADDR'] || ''; // URL of the Hub
const client = getInsecureHubRpcClient(HUB_URL);
// const client = getSSLHubRpcClient(HUB_URL); if you want to use SSL
// If your Hub requires authentication, use the following instead:
// const authMetadata = getAuthMetadata(HUB_USERNAME, HUB_PASSWORD);
// const result = await client.submitMessage(signerAdd);
const result = await client.submitMessage(signerAdd);
result.isOk() ? console.log('SignerAdd was published successfully!') : console.log(result.error);