diff --git a/docs/contracts.md b/docs/contracts.md index 7906a8d5b..070d03968 100644 --- a/docs/contracts.md +++ b/docs/contracts.md @@ -203,22 +203,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> => { @@ -245,8 +244,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); diff --git a/docs/examples/contracts/contract-delegation-ERC20.ts b/docs/examples/contracts/contract-delegation-ERC20.ts index 6138b99b7..d5495c84e 100644 --- a/docs/examples/contracts/contract-delegation-ERC20.ts +++ b/docs/examples/contracts/contract-delegation-ERC20.ts @@ -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, @@ -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' @@ -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> => { @@ -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); diff --git a/docs/examples/transactions/fee-delegation.ts b/docs/examples/transactions/fee-delegation.ts index 913eaa923..851ab06e0 100644 --- a/docs/examples/transactions/fee-delegation.ts +++ b/docs/examples/transactions/fee-delegation.ts @@ -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 @@ -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); diff --git a/docs/examples/transactions/full-flow-delegator-private-key.ts b/docs/examples/transactions/full-flow-delegator-private-key.ts index 99b7c978a..0187ec338 100644 --- a/docs/examples/transactions/full-flow-delegator-private-key.ts +++ b/docs/examples/transactions/full-flow-delegator-private-key.ts @@ -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' @@ -50,8 +50,9 @@ const providerWithDelegationEnabled = new VeChainProvider( } ], { + // The term `delegator` will be deprecated soon and renamed `gasPayer`. delegator: { - delegatorPrivateKey: delegatorAccount.privateKey + delegatorPrivateKey: gasPayerAccount.privateKey } } ), @@ -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(); diff --git a/docs/examples/transactions/full-flow-delegator-url.ts b/docs/examples/transactions/full-flow-delegator-url.ts index 71822faff..453414efe 100644 --- a/docs/examples/transactions/full-flow-delegator-url.ts +++ b/docs/examples/transactions/full-flow-delegator-url.ts @@ -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' }; @@ -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 } } ), @@ -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(); diff --git a/docs/templates/contracts.md b/docs/templates/contracts.md index 76b5a70f5..ca7a16c46 100644 --- a/docs/templates/contracts.md +++ b/docs/templates/contracts.md @@ -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) diff --git a/docs/transactions.md b/docs/transactions.md index 26bbcfa32..805b1921f 100644 --- a/docs/transactions.md +++ b/docs/transactions.md @@ -164,17 +164,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 @@ -464,8 +464,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' @@ -485,8 +485,9 @@ const providerWithDelegationEnabled = new VeChainProvider( } ], { + // The term `delegator` will be deprecated soon and renamed `gasPayer`. delegator: { - delegatorPrivateKey: delegatorAccount.privateKey + delegatorPrivateKey: gasPayerAccount.privateKey } } ), @@ -571,8 +572,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' }; @@ -590,8 +591,9 @@ const providerWithDelegationEnabled = new VeChainProvider( } ], { + // The term `delegator` will be deprecated soon and renamed `gasPayer`. delegator: { - delegatorUrl: delegatorAccount.URL + delegatorUrl: gasPayerAccount.URL } } ),