Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
cool declare+deploy+invoke+call success (#22)
Browse files Browse the repository at this point in the history
* add deploy erc20 init

Signed-off-by: Qiang Zhou <[email protected]>
  • Loading branch information
zhouqiang-cl authored Feb 2, 2024
1 parent 76ef5ce commit 44591f8
Show file tree
Hide file tree
Showing 5 changed files with 1,489 additions and 4 deletions.
40 changes: 37 additions & 3 deletions cairoVM/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func main() {

// declare TX
declareTx, class, err := cairoVM.NewDeclare(
"data/erc20.sierra.json",
"data/erc20.casm.json",
"data/cool.sierra.json",
"data/cool.casm.json",
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -68,7 +68,7 @@ func main() {
fmt.Println("call response", utils.FeltToBigInt(resp[0]))

// deployContract TX
deployTx, err := cairoVM.NewDeployERC20()
deployTx, err := cairoVM.NewDeployCool()
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -102,4 +102,38 @@ func main() {
}
fmt.Println("call response", utils.FeltToBigInt(resp[0]))

deployTx, err = cairoVM.NewDeployCoolOld()
if err != nil {
panic(err)
}

trace, err = vm.HandleInvokeTx(deployTx) // Assuming there is a HandleInvokeTx function
if err != nil {
panic(err)
}
spew.Dump(trace)

invokeTx, err = cairoVM.NewDeployInvokeTestCoolOld()
if err != nil {
panic(err)
}

trace, err = vm.HandleInvokeTx(invokeTx) // Assuming there is a HandleInvokeTx function
if err != nil {
panic(err)
}

new_address, _ = new(felt.Felt).SetString("0x77fcc62a59a2160f099493fcd0466c526120320c164a62a72c6ac9931db34d9")

resp, err = vm.HandleCall(&rpc.FunctionCall{
ContractAddress: *new_address,
EntryPointSelector: *utils.GetSelectorFromNameFelt("get_value"),
},
callClassHash,
)
if err != nil {
panic(err)
}
fmt.Println("call response", utils.FeltToBigInt(resp[0]))

}
85 changes: 84 additions & 1 deletion cairoVM/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
deployContractMethod string = "deployContract"
)

func NewDeployERC20() (*core.InvokeTransaction, error) {
func NewDeployCool() (*core.InvokeTransaction, error) {
//InvokeTx := rpc.InvokeTxnV1{
// Version: rpc.TransactionV1,
// Type: rpc.TransactionType_Invoke,
Expand Down Expand Up @@ -96,3 +96,86 @@ func NewDeployInvokeTest() (*core.InvokeTransaction, error) {
return &tx, nil

}

func NewDeployCoolOld() (*core.InvokeTransaction, error) {
//InvokeTx := rpc.InvokeTxnV1{
// Version: rpc.TransactionV1,
// Type: rpc.TransactionType_Invoke,
//}

// using UniversalDeploy address
contractAddress := new(felt.Felt).SetUint64(1)

classHash, _ := new(felt.Felt).SetString("0x47f93257c3a6e42fc71162a646b3223dfad27c2d994f97f333492c66e31b8c8")

salt, _ := new(felt.Felt).SetString("0x53eb1d3593b1fe9a8369a023ffa5d07d3b2050841cb75ad6ef00698d9307d10")

uniq := new(felt.Felt).SetUint64(1)

calldataLength := new(felt.Felt).SetUint64(0)

// calldata := felt.Felt{}

// params := new(felt.Felt).SetUint64(8088)
// Building the functionCall struct, where :
FnCall := rpc.FunctionCall{
ContractAddress: contractAddress, //contractAddress is the contract that we want to call
EntryPointSelector: utils.GetSelectorFromNameFelt(deployContractMethod), //this is the function that we want to call
Calldata: []*felt.Felt{classHash, salt, uniq, calldataLength}, //this is the data that we want to pass to the function
}

txCallData := account.FmtCallDataCairo2([]rpc.FunctionCall{FnCall})

fmt.Println("invoke calldata = ", txCallData)

nonce := new(felt.Felt).SetUint64(4)
tx := core.InvokeTransaction{
Nonce: nonce,
MaxFee: &felt.Zero,
Version: new(core.TransactionVersion).SetUint64(1),
ContractAddress: contractAddress,
EntryPointSelector: utils.GetSelectorFromNameFelt(deployContractMethod),
CallData: txCallData,
// CallData: []*felt.Felt{randata},
}

return &tx, nil

}

func NewDeployInvokeTestCoolOld() (*core.InvokeTransaction, error) {
//InvokeTx := rpc.InvokeTxnV1{
// Version: rpc.TransactionV1,
// Type: rpc.TransactionType_Invoke,
//}

// Converting the contractAddress from hex to felt
// contractAddress := new(felt.Felt).SetUint64(2)
contractAddress, _ := new(felt.Felt).SetString("0x77fcc62a59a2160f099493fcd0466c526120320c164a62a72c6ac9931db34d9")

params := new(felt.Felt).SetUint64(1111)
// Building the functionCall struct, where :
FnCall := rpc.FunctionCall{
ContractAddress: contractAddress, //contractAddress is the contract that we want to call
EntryPointSelector: utils.GetSelectorFromNameFelt(contractMethod), //this is the function that we want to call
Calldata: []*felt.Felt{params}, //this is the data that we want to pass to the function
}

txCallData := account.FmtCallDataCairo2([]rpc.FunctionCall{FnCall})

fmt.Println("invoke calldata = ", txCallData)

nonce := new(felt.Felt).SetUint64(5)
tx := core.InvokeTransaction{
Nonce: nonce,
MaxFee: &felt.Zero,
Version: new(core.TransactionVersion).SetUint64(1),
ContractAddress: contractAddress,
EntryPointSelector: utils.GetSelectorFromNameFelt(contractMethod),
CallData: txCallData,
// CallData: []*felt.Felt{randata},
}

return &tx, nil

}
1 change: 1 addition & 0 deletions cairoVM/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cairoVM

import (
"fmt"

"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/account"
Expand Down
Loading

0 comments on commit 44591f8

Please sign in to comment.