@evstack/evnode-viem
v0.1.1
Published
Viem client extension for EvNode transactions
Downloads
163
Readme
@evstack/evnode-viem
Viem client extension for EvNode transactions (type 0x76).
Installation
npm install @evstack/evnode-viem viemUsage
Basic Transaction
import { createClient, http } from 'viem';
import { privateKeyToAccount, sign } from 'viem/accounts';
import { createEvnodeClient } from '@evstack/evnode-viem';
const client = createClient({
transport: http('http://localhost:8545'),
});
const account = privateKeyToAccount('0x...');
const evnode = createEvnodeClient({
client,
executor: {
address: account.address,
signHash: async (hash) => sign({ hash, privateKey: '0x...' }),
},
});
// Send a transaction
const txHash = await evnode.send({
calls: [
{ to: '0x...', value: 0n, data: '0x' },
],
});Batch Transactions
EvNode transactions support multiple calls in a single transaction:
const txHash = await evnode.send({
calls: [
{ to: recipient1, value: 1000000000000000n, data: '0x' },
{ to: recipient2, value: 1000000000000000n, data: '0x' },
],
});Sponsored Transactions
A sponsor can pay gas fees on behalf of the executor:
const evnode = createEvnodeClient({
client,
executor: { address: executorAddr, signHash: executorSignFn },
sponsor: { address: sponsorAddr, signHash: sponsorSignFn },
});
// Create intent (signed by executor)
const intent = await evnode.createIntent({
calls: [{ to: '0x...', value: 0n, data: '0x' }],
});
// Sponsor signs and sends
const txHash = await evnode.sponsorAndSend({ intent });API
createEvnodeClient(options)
Creates a new EvNode client.
Options:
client- Viem Client instanceexecutor- (optional) Default executor signersponsor- (optional) Default sponsor signer
Client Methods
send(args)- Sign and send an EvNode transactioncreateIntent(args)- Create a sponsorable intentsponsorIntent(args)- Add sponsor signature to an intentsponsorAndSend(args)- Sponsor and send in one callserialize(signedTx)- Serialize a signed transactiondeserialize(hex)- Deserialize a signed transaction
Utility Functions
computeExecutorSigningHash(tx)- Get hash for executor to signcomputeSponsorSigningHash(tx, executorAddress)- Get hash for sponsor to signcomputeTxHash(signedTx)- Get transaction hashrecoverExecutor(signedTx)- Recover executor address from signaturerecoverSponsor(tx, executorAddress)- Recover sponsor address from signatureestimateIntrinsicGas(calls)- Estimate minimum gas for calls
License
MIT
