silvestrevivo / solana-svelte-counter Goto Github PK
View Code? Open in Web Editor NEWDemo for the Svelte wallet adapter built in Svelte and Anchor
Demo for the Svelte wallet adapter built in Svelte and Anchor
$'npm run dev'
'
TypeError: Cannot read properties of undefined (reading 'address')
at eval (/src/lib/AnchorConnectionProvider.svelte:27:47)
at Object.$$render (/mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/svelte/internal/index.js:1684:22)
at eval (/src/routes/__layout.svelte:46:103)
at Object.$$render (/mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/svelte/internal/index.js:1684:22)
at root.svelte:37:45
at $$render (/mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/svelte/internal/index.js:1684:22)
at Object.render (/mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/svelte/internal/index.js:1692:26)
at render_response (file:///mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/@sveltejs/kit/dist/chunks/index.js:1070:28)
at async respond_with_error (file:///mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/@sveltejs/kit/dist/chunks/index.js:1691:10)
at async respond$1 (file:///mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/@sveltejs/kit/dist/chunks/index.js:1942:4)
TypeError: Cannot read properties of undefined (reading 'address')
at eval (/src/lib/AnchorConnectionProvider.svelte:27:47)
at Object.$$render (/mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/svelte/internal/index.js:1684:22)
at eval (/src/routes/__layout.svelte:46:103)
at Object.$$render (/mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/svelte/internal/index.js:1684:22)
at root.svelte:37:45
at $$render (/mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/svelte/internal/index.js:1684:22)
at Object.render (/mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/svelte/internal/index.js:1692:26)
at render_response (file:///mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/@sveltejs/kit/dist/chunks/index.js:1070:28)
at async respond_with_error (file:///mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/@sveltejs/kit/dist/chunks/index.js:1691:10)
at async respond$1 (file:///mnt/c/Users/shane/Desktop/solana-svelte-counter/solana-svelte-counter/app/node_modules/@sveltejs/kit/dist/chunks/index.js:1942:4)
'
Just following the instructions:
Make sure that you have Solana locally in localhost and change all the devnet references to localhost
$ npx anchor localnet
Workspace configuration error: Cluster must be one of [localnet, testnet, mainnet, devnet] or be an http or https url
What I ended up doing was setting this in my Anchor.toml
- I'm not 100% sure it's correct (I have little Anchor experience, hence not sending a PR) but it worked:
[programs.localnet]
solana_svelte_counter = "C7SGr2s3HdBuEveTahL9H3CsXQDwxkYEUSRPeJAVeDN5"
[registry]
url = "https://anchor.projectserum.com"
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"
[scripts]
test = "mocha -t 1000000 tests/"
Does that sound correct? If so let me know and I will add the to the PR I will send - I have a bunch of small fixes to contribute!
AutoConnect is not working correctly. There are two possibilities:
My theory is that is an UI error of the current solution I made. Checking the code, it seems that we are clicking on select()
and, since autoConnect
is true, automatically the connect()
function is triggered. That's why when autoConnect
is false, the wallet is not popping up.
I made a change locally and it is working. Even in the Vue implementation works like that. The select()
function is to select the adapter, and the connect()
is to popup the wallet selected. See here the Vue implementation:
https://github.com/solana-labs/wallet-adapter/pull/118/files
The change I made was:
<script>
....
type WalletProvider = { id: number; text: string };
let walletProviders: WalletProvider[] = [
{ id: 1, text: `Phantom` },
{ id: 2, text: `Slope` },
{ id: 3, text: `Solflare` }
];
let selected;
$: selected && selectWallet(selected.text);
</script>
<div class="wrapper-content">
{#if $walletStore?.connected}
<button on:click={() => $walletStore.disconnect()}>disconnect wallet</button>
{:else}
<p>Select wallet</p>
<select bind:value={selected}>
{#each walletProviders as walletProvider}
<option value={walletProvider}>
{walletProvider.text}
</option>
{/each}
</select>
{#if selected}
<button on:click={() => $walletStore.connect()}>connect {selected.text}</button>
{/if}
{/if}
</div>
Hey, hello.
It's great to have work as yours as a reference. Working with new technologies with little documentation and examples I'm feeling deep appreciation for having people who provide like that.
Using your groundwork form your demo-app and the svele-on-solana
packages I'm trying to deepen my knowledge. Where I'm running into some problems is trying to fetch data.
How would you access the program variable to only fetch data?
let data
const getData = async () => {
data = await $workSpace.program.account.baseAccount.all()
// alternatively something like
data = await $workSpace.program.account.baseAccount.fetch(
$workSpace.baseAccount.publicKey
);
console.log(data);
return data;
};
Executing something like the example function above gives the error TypeError: Cannot read properties of undefined (reading 'program')
I know, this is an issue that isn't really related to the repo. It's more just me having difficulties to get ahead with something I don't quiet understand yet. Which is a rather egoistic thing to ask here. Anyway I'm opening this and hoping you can maybe provide an example inside the packages or demo app how fetch data outside the already provided RPC functions.
Sending love and blessings
Edit:
Trying for two more hours, and coming back more confused that the same code works in some situations when I'm connected to a wallet. But most of the time trying to fetch it's the Error: Uncaught (in promise) TypeError: can't access property "program", $workSpace is undefined
. Possibly someone can tell what I am doing wrong.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.