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

1658 bnc - part 1 #1777

Merged
merged 7 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions docs/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,21 @@ You can specify revisions (`best` or `finalized`) for read functions, similar to

## Delegating a Contract Call

VeChain supports delegated contract calls where fees are paid by the delegator.
VeChain supports delegated contract calls where fees are paid by the gas-payer.

```typescript { name=contract-delegation-erc20, category=example }
const thorSoloClient = ThorClient.at(THOR_SOLO_URL);
const provider = new VeChainProvider(
thorSoloClient,
new ProviderInternalBaseWallet([deployerAccount], {
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorPrivateKey: delegatorAccount.privateKey
delegatorPrivateKey: gasPayerAccount.privateKey
}
}),
true
);
const signer = (await provider.getSigner(
deployerAccount.address
)) as VeChainSigner;
const signer = await provider.getSigner(deployerAccount.address);

// Defining a function for deploying the ERC20 contract
const setupERC20Contract = async (): Promise<Contract<typeof ERC20_ABI>> => {
Expand All @@ -244,8 +243,7 @@ const transferResult = await contract.transact.transfer(
);

// Wait for the transfer transaction to complete and obtain its receipt
const transactionReceiptTransfer =
(await transferResult.wait()) as TransactionReceipt;
const transactionReceiptTransfer = await transferResult.wait();

// Asserting that the transaction has not been reverted
expect(transactionReceiptTransfer.reverted).toEqual(false);
Expand Down
16 changes: 7 additions & 9 deletions docs/examples/contracts/contract-delegation-ERC20.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ERC20_ABI, Hex, HexUInt } from '@vechain/sdk-core';
import { ERC20_ABI, HexUInt } from '@vechain/sdk-core';
import {
type Contract,
ProviderInternalBaseWallet,
Expand All @@ -23,8 +23,8 @@ const deployerAccount: ProviderInternalWalletAccount = {
address: '0xf02f557c753edf5fcdcbfe4c1c3a448b3cc84d54'
};

// Defining the delegator account, which has VTHO for transaction costs
const delegatorAccount = {
// Defining the gas-payer account, which has VTHO for transaction costs
const gasPayerAccount = {
privateKey:
'521b7793c6eb27d137b617627c6b85d57c0aa303380e9ca4e30a30302fbc6676',
address: '0x062F167A905C1484DE7e75B88EDC7439f82117DE'
Expand All @@ -36,15 +36,14 @@ const thorSoloClient = ThorClient.at(THOR_SOLO_URL);
const provider = new VeChainProvider(
thorSoloClient,
new ProviderInternalBaseWallet([deployerAccount], {
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorPrivateKey: delegatorAccount.privateKey
delegatorPrivateKey: gasPayerAccount.privateKey
}
}),
true
);
const signer = (await provider.getSigner(
deployerAccount.address
)) as VeChainSigner;
const signer = await provider.getSigner(deployerAccount.address);

// Defining a function for deploying the ERC20 contract
const setupERC20Contract = async (): Promise<Contract<typeof ERC20_ABI>> => {
Expand All @@ -71,8 +70,7 @@ const transferResult = await contract.transact.transfer(
);

// Wait for the transfer transaction to complete and obtain its receipt
const transactionReceiptTransfer =
(await transferResult.wait()) as TransactionReceipt;
const transactionReceiptTransfer = await transferResult.wait();

// Asserting that the transaction has not been reverted
expect(transactionReceiptTransfer.reverted).toEqual(false);
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/transactions/fee-delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ const body: TransactionBody = {
// 4 - Create private keys of sender and delegate

const nodeDelegate = HDKey.fromMnemonic(Mnemonic.of());
const delegatorPrivateKey = nodeDelegate.privateKey;
const gasPayerPrivateKey = nodeDelegate.privateKey;

// 5 - Get address of delegate

const delegatorAddress = Address.ofPublicKey(nodeDelegate.publicKey).toString();
const gasPayerAddress = Address.ofPublicKey(nodeDelegate.publicKey).toString();

// 6 - Sign transaction as sender and delegate

const signedTransaction = Transaction.of(body).signAsSenderAndGasPayer(
HexUInt.of(senderAccount.privateKey).bytes,
HexUInt.of(delegatorPrivateKey).bytes
HexUInt.of(gasPayerPrivateKey).bytes
);

// 7 - Encode transaction
Expand All @@ -85,4 +85,4 @@ const decodedTx = Transaction.decode(encodedRaw, true);
// END_SNIPPET: FeeDelegationSnippet

expect(decodedTx.isDelegated).toBeTruthy();
expect(decodedTx.gasPayer.toString()).toBe(delegatorAddress);
expect(decodedTx.gasPayer.toString()).toBe(gasPayerAddress);
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const senderAccount: { privateKey: string; address: string } = {
address: '0x7a28e7361fd10f4f058f9fefc77544349ecff5d6'
};

// Delegator account with private key
const delegatorAccount: { privateKey: string; address: string } = {
// Gas-payer account with private key
const gasPayerAccount: { privateKey: string; address: string } = {
privateKey:
'521b7793c6eb27d137b617627c6b85d57c0aa303380e9ca4e30a30302fbc6676',
address: '0x062F167A905C1484DE7e75B88EDC7439f82117DE'
Expand All @@ -50,8 +50,9 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
lucanicoladebiasi marked this conversation as resolved.
Show resolved Hide resolved
delegator: {
delegatorPrivateKey: delegatorAccount.privateKey
delegatorPrivateKey: gasPayerAccount.privateKey
}
lucanicoladebiasi marked this conversation as resolved.
Show resolved Hide resolved
}
),
Expand Down Expand Up @@ -119,7 +120,7 @@ const txReceipt = await thorSoloClient.transactions.waitForTransaction(
// Check the signed transaction
expect(delegatedSigned.isSigned).toEqual(true);
expect(delegatedSigned.isDelegated).toEqual(true);
expect(delegatedSigned.gasPayer.toString()).toEqual(delegatorAccount.address);
expect(delegatedSigned.gasPayer.toString()).toEqual(gasPayerAccount.address);

// Check the transaction receipt
expect(txReceipt).toBeDefined();
Expand Down
9 changes: 5 additions & 4 deletions docs/examples/transactions/full-flow-delegator-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const senderAccount: {
address: '0x571E3E1fBE342891778151f037967E107fb89bd0'
};

// Delegator account with private key
const delegatorAccount = {
// Gas-payer account with private key
const gasPayerAccount = {
URL: 'https://sponsor-testnet.vechain.energy/by/269'
};

Expand All @@ -54,8 +54,9 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorUrl: delegatorAccount.URL
delegatorUrl: gasPayerAccount.URL
}
lucanicoladebiasi marked this conversation as resolved.
Show resolved Hide resolved
}
),
Expand Down Expand Up @@ -123,7 +124,7 @@ const txReceipt = await thorClient.transactions.waitForTransaction(
// Check the signed transaction
expect(delegatedSigned.isSigned).toEqual(true);
expect(delegatedSigned.isDelegated).toEqual(true);
// expect(signedTx.delegator).toEqual(delegatorAccount.address); ---
// expect(signedTx.delegator).toEqual(gasPayerAccount.address); ---

// Check the transaction receipt
expect(txReceipt).toBeDefined();
Expand Down
2 changes: 1 addition & 1 deletion docs/templates/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ You can specify revisions (`best` or `finalized`) for read functions, similar to

## Delegating a Contract Call

VeChain supports delegated contract calls where fees are paid by the delegator.
VeChain supports delegated contract calls where fees are paid by the gas-payer.

[ERC20FunctionCallDelegatedSnippet](examples/contracts/contract-delegation-ERC20.ts)
20 changes: 11 additions & 9 deletions docs/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ const body: TransactionBody = {
// 4 - Create private keys of sender and delegate

const nodeDelegate = HDKey.fromMnemonic(Mnemonic.of());
const delegatorPrivateKey = nodeDelegate.privateKey;
const gasPayerPrivateKey = nodeDelegate.privateKey;

// 5 - Get address of delegate

const delegatorAddress = Address.ofPublicKey(nodeDelegate.publicKey).toString();
const gasPayerAddress = Address.ofPublicKey(nodeDelegate.publicKey).toString();

// 6 - Sign transaction as sender and delegate

const signedTransaction = Transaction.of(body).signAsSenderAndGasPayer(
HexUInt.of(senderAccount.privateKey).bytes,
HexUInt.of(delegatorPrivateKey).bytes
HexUInt.of(gasPayerPrivateKey).bytes
);

// 7 - Encode transaction
Expand Down Expand Up @@ -463,8 +463,8 @@ const senderAccount: { privateKey: string; address: string } = {
address: '0x7a28e7361fd10f4f058f9fefc77544349ecff5d6'
};

// Delegator account with private key
const delegatorAccount: { privateKey: string; address: string } = {
// Gas-payer account with private key
const gasPayerAccount: { privateKey: string; address: string } = {
privateKey:
'521b7793c6eb27d137b617627c6b85d57c0aa303380e9ca4e30a30302fbc6676',
address: '0x062F167A905C1484DE7e75B88EDC7439f82117DE'
Expand All @@ -484,8 +484,9 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorPrivateKey: delegatorAccount.privateKey
delegatorPrivateKey: gasPayerAccount.privateKey
}
}
),
Expand Down Expand Up @@ -570,8 +571,8 @@ const senderAccount: {
address: '0x571E3E1fBE342891778151f037967E107fb89bd0'
};

// Delegator account with private key
const delegatorAccount = {
// Gas-payer account with private key
const gasPayerAccount = {
URL: 'https://sponsor-testnet.vechain.energy/by/269'
};

Expand All @@ -589,8 +590,9 @@ const providerWithDelegationEnabled = new VeChainProvider(
}
],
{
// The term `delegator` will be deprecated soon and renamed `gasPayer`.
delegator: {
delegatorUrl: delegatorAccount.URL
delegatorUrl: gasPayerAccount.URL
}
}
),
Expand Down
Loading
Loading