Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Aeternity Snap #73

Closed
nikita-fuchs opened this issue Sep 12, 2024 · 8 comments
Closed

Support Aeternity Snap #73

nikita-fuchs opened this issue Sep 12, 2024 · 8 comments
Assignees

Comments

@nikita-fuchs
Copy link
Collaborator

Hey @yusufseyrek , here is for the snap:

  1. What is a snap really?
    It is something like a plugin to metamask that allows some operations on an a key that is allegedly stored somehow somewhere in metamask, but you can't even see it in the account management. It is all not even an MVP yet, don't expect any product like features.

  2. how do I interact with this account?
    The regular SDK does not support this (yet), there is a snap SDK and example code.
    You can find a basic setup example code here: https://github.com/4-point-0/aeternity-snap and use the example application to find some orientation.

  3. how do I make a contract call?
    Here comes the fun part: The snap SDK supports only signing and sending transactions, so before you can call a contract actually, @davidyuk will point you to some functionality of aeternity's JS-SDK how you can get the correct transaction and calldata put together and have it as a raw transaction object to put into that signAndSend function of the snap.

Much success !

@yusufseyrek
Copy link
Collaborator

Completed my assessment about MM AE Snap. Best to implement it after AE SDK adopted it.

@yusufseyrek yusufseyrek closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2024
@davidyuk
Copy link
Member

davidyuk commented Oct 5, 2024

I've merged snap support to develop branch, will release it in a couple of weeks
aeternity/aepp-sdk-js#2023

Regarding contract calls, the idea is to use Contract as usual, providing an instance of AccountMetamask as an account.

@yusufseyrek yusufseyrek reopened this Oct 5, 2024
@yusufseyrek
Copy link
Collaborator

Thanks @davidyuk, I will pick this up.

@nikita-fuchs
Copy link
Collaborator Author

damn @davidyuk 🚀 can you please add documentation for that also ?

@davidyuk
Copy link
Member

I wrote a guide on this topic, and also there should be an entry in API reference, but the docs build is currently broken on develop. I will fix it before the release.

@yusufseyrek
Copy link
Collaborator

Are smart contract calls will work with this setup right away too? Or do we need to get the raw tx data send with this sign method?

If raw data needed, could you also provide an example for smart contract calls too?

@davidyuk
Copy link
Member

Smart contract calls work! There is no need to handle raw tx manually, here is an example

Replace the contents of test/environment/browser.html in sdk repo on develop branch
Open developer console
<script src="../../dist/aepp-sdk.browser-script.js"></script>
<script type="text/javascript">
const { Node, AeSdk, MemoryAccount, CompilerHttp, Contract, AccountMetamaskFactory } = Aeternity;

const contractSourceCode = `
contract Test =
entrypoint foo(x : int) = x * 2
`;
const aeSdk = new AeSdk({
  nodes: [{ name: 'testnet', instance: new Node('https://testnet.aeternity.io') }],
  onCompiler: new CompilerHttp('https://v8.compiler.aepps.com'),
});
const factory = new AccountMetamaskFactory();

(async () => {
  await factory.installSnap();
  aeSdk.addAccount(await factory.initialize(0), { select: true });
  console.log('Metamask account', aeSdk.address);

  const contract = await Contract.initialize({
    ...aeSdk.getContext(),
    address: 'ct_s6EhAmkMX46gk5MJxrwtD3sJFzUT1HcnoT3tyYBqT4LZsiUri',
    sourceCode: contractSourceCode,
  });
  // const deployInfo = await contract.$deploy([]);
  // console.log('Contract deployed at', deployInfo.address);
  const { decodedResult } = await contract.foo(21, { callStatic: false });
  console.log('Call result', decodedResult);
})();
</script>

@yusufseyrek
Copy link
Collaborator

Awesome, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants