-
Notifications
You must be signed in to change notification settings - Fork 2
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
Comments
Completed my assessment about MM AE Snap. Best to implement it after AE SDK adopted it. |
I've merged snap support to develop branch, will release it in a couple of weeks Regarding contract calls, the idea is to use Contract as usual, providing an instance of AccountMetamask as an account. |
Thanks @davidyuk, I will pick this up. |
damn @davidyuk 🚀 can you please add documentation for that also ? |
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. |
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? |
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 branchOpen 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> |
Awesome, thanks a lot! |
Hey @yusufseyrek , here is for the snap:
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.
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.
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 !
The text was updated successfully, but these errors were encountered: