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

Viem JSON-RPC + encrypted transactions #246

Open
CedarMist opened this issue Dec 18, 2023 · 1 comment
Open

Viem JSON-RPC + encrypted transactions #246

CedarMist opened this issue Dec 18, 2023 · 1 comment
Labels
client js Pull requests that update JS code s:planned Status: work on this issue is scheduled

Comments

@CedarMist
Copy link
Member

As per the Ethers v5 & Ethers v6 standalone tests in #239

Would like to make sure Viem works and the transaction, simulate & estimate calls have encrypted calldata before we can say we officially support Viem. As we don't want people to use Sapphire + viem and think it's encrypted but it's not...

The following is a snippet of deploying the TestERC20Token contract, needs to be adapted to work with Viem.

import { http, defineChain, createWalletClient, createPublicClient, getContract } from 'viem'
import { privateKeyToAccount } from "viem/accounts";
import { TestErc20Token } from "./TestErc20Token.js";
import { assert } from 'console';

async function main () {
    const sapphireLocalnet = defineChain({
        id: 0x5afd,
        name: 'Sapphire-Localnet',
        network: 'sapphire-localnet',
        nativeCurrency: {
            decimals: 18,
            name: 'Sapphire Localnet Test',
            symbol: 'TEST'
        },
        rpcUrls: {
            default: {
                http: ['http://127.0.0.1:8545']
            },
            public: {
                http: ['http://127.0.0.1:8545']
            }
        }
    });

    const account = privateKeyToAccount('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80');

    const walletClient = createWalletClient({
        account,
        chain: sapphireLocalnet,
        transport: http('http://127.0.0.1:8545')
    });

    const publicClient = createPublicClient({
        chain: sapphireLocalnet,
        transport: http('http://127.0.0.1:8545')
    })

    const deployHash = await walletClient.deployContract({
        abi: TestErc20Token.abi,
        account,
        bytecode: TestErc20Token.bytecode
    });
    console.log('deployHash', deployHash);
    const receipt = await publicClient.waitForTransactionReceipt({hash: deployHash});
    console.log('deployed', receipt.contractAddress!);

    const contract = getContract({
        address: receipt.contractAddress!,
        abi: TestErc20Token.abi,
        publicClient,
        walletClient: walletClient
    });

    const mintTx = await contract.write.mint([account.address, 100n]);
    console.log('mint() tx', mintTx);
    await publicClient.waitForTransactionReceipt({hash: mintTx});

    assert(await contract.read.totalSupply() == 100n);
}

await main ();
@CedarMist CedarMist added s:planned Status: work on this issue is scheduled js Pull requests that update JS code client labels Dec 18, 2023
@CedarMist
Copy link
Member Author

#164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client js Pull requests that update JS code s:planned Status: work on this issue is scheduled
Projects
None yet
Development

No branches or pull requests

1 participant