@@ -764,6 +764,132 @@ async send(request: UserRequest): Promise<UserRequest> {
764
764
}
765
765
```
766
766
767
+ ### Dapp Funded Transactions
768
+
769
+
770
+ #### A ` TxExecutionRequestComponent ` for the Dapp
771
+
772
+ ``` ts
773
+ export class DefaultDappInterface implements AccountInterface {
774
+ constructor (
775
+ private completeAddress : CompleteAddress ,
776
+ private userAuthWitnessProvider : AuthWitnessProvider ,
777
+ private dappEntrypointAddress : AztecAddress ,
778
+ private chainId : number = DEFAULT_CHAIN_ID ,
779
+ private version : number = DEFAULT_VERSION ,
780
+ ) {}
781
+
782
+ async adaptTxExecutionRequest(
783
+ builder : TxExecutionRequestBuilder ,
784
+ userRequest : UserRequest
785
+ ): Promise <void > {
786
+ if (builder .appFunctionCalls .length !== 1 ) {
787
+ throw new Error (` Expected exactly 1 function call, got ${calls .length } ` );
788
+ }
789
+ if (builder .setupFunctionCalls .length !== 0 ) {
790
+ throw new Error (` Expected exactly 0 setup function calls, got ${calls .length } ` );
791
+ }
792
+ const payload = EntrypointPayload .fromFunctionCalls (builder .appFunctionCalls );
793
+ const abi = this .getEntrypointAbi ();
794
+
795
+ const entrypointPackedArgs = PackedValues .fromValues (encodeArguments (abi , [payload , this .completeAddress .address ]));
796
+ const functionSelector = FunctionSelector .fromNameAndParameters (abi .name , abi .parameters );
797
+
798
+ const innerHash = computeInnerAuthWitHash ([Fr .ZERO , functionSelector .toField (), entrypointPackedArgs .hash ]);
799
+ const outerHash = computeOuterAuthWitHash (
800
+ this .dappEntrypointAddress ,
801
+ new Fr (this .chainId ),
802
+ new Fr (this .version ),
803
+ innerHash ,
804
+ );
805
+ const authWitness = await this .userAuthWitnessProvider .createAuthWit (outerHash );
806
+
807
+ builder
808
+ .setOrigin (this .dappEntrypointAddress )
809
+ .setTxContext ({
810
+ chainId: this .chainId ,
811
+ version: this .version ,
812
+ gasSettings: userRequest .gasSettings ,
813
+ })
814
+ .setFunctionSelector (functionSelector )
815
+ .setFirstCallArgsHash (entrypointPackedArgs .hash )
816
+ .setArgsOfCalls ([... payload .packedArguments , entrypointPackedArgs ])
817
+ .addAuthWitness (authWitness );
818
+
819
+ }
820
+
821
+
822
+ createAuthWit(messageHash : Fr ): Promise <AuthWitness > {
823
+ return this .authWitnessProvider .createAuthWit (messageHash );
824
+ }
825
+
826
+ getCompleteAddress(): CompleteAddress {
827
+ return this .completeAddress ;
828
+ }
829
+
830
+ getAddress(): AztecAddress {
831
+ return this .completeAddress .address ;
832
+ }
833
+
834
+ getChainId(): Fr {
835
+ return this .chainId ;
836
+ }
837
+
838
+ getVersion(): Fr {
839
+ return this .version ;
840
+ }
841
+
842
+ private getEntrypointAbi() {
843
+ return {
844
+ name: ' entrypoint' ,
845
+ // ... same as before
846
+ }
847
+ }
848
+
849
+ }
850
+ ```
851
+
852
+ #### Create the wallet as normal
853
+
854
+ ``` ts
855
+ export async function getDappWallet(
856
+ pxe : PXE ,
857
+ accountAddress : AztecAddress ,
858
+ dappAddress : AztecAddress ,
859
+ userAuthWitnessProvider : AuthWitnessProvider ,
860
+ ): Promise <AccountWallet > {
861
+ const completeAddress = await pxe .getRegisteredAccount (accountAddress );
862
+ if (! completeAddress ) {
863
+ throw new Error (` Account ${address } not found ` );
864
+ }
865
+ const nodeInfo = await pxe .getNodeInfo ();
866
+ const entrypoint = new DefaultDappInterface (completeAddress , userAuthWitnessProvider , dappAddress );
867
+ return new AccountWallet (pxe , entrypoint );
868
+ }
869
+
870
+
871
+ const schnorr = new SchnorrAccountContract (signingPrivateKey );
872
+ const authWitProvider = schnorr .getAuthWitnessProvider ();
873
+ const aliceDappWrappedWallet = await getDappWallet (pxe , aliceAddress , dappAddress , userAuthWitnessProvider );
874
+
875
+ const { request : deployAliceAccountRequest } = await aliceDappWrappedWallet .simulate ({
876
+ calls: [{
877
+ contractInstance: bananaCoinInstance ,
878
+ functionName: ' transfer' ,
879
+ args: {
880
+ from: aliceAddress ,
881
+ to: bobAddress ,
882
+ value: privateBalance ,
883
+ nonce: 0n
884
+ },
885
+ }],
886
+ paymentMethod: new NoFeePaymentMethod (),
887
+ })
888
+
889
+ ```
890
+
891
+
892
+
767
893
### Concerns
768
894
769
895
#### ` UserRequest ` is a kitchen sink
0 commit comments