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

cool declare+deploy+invoke+call success #22

Merged
merged 7 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 12 additions & 1 deletion cairoVM/cmd/main.go
Original file line number Diff line number Diff line change
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,15 @@ func main() {
}
fmt.Println("call response", utils.FeltToBigInt(resp[0]))

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

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

}
60 changes: 59 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,61 @@ func NewDeployInvokeTest() (*core.InvokeTransaction, error) {
return &tx, nil

}

func NewDeployERC20() (*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("0x781eaffc0d732cae7cf40b7488bba82d23711b7abfc06fee4c4dd2821155e18")

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

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

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

name := felt.Felt{}
name.SetString("ERC20")
symbol := felt.Felt{}
symbol.SetString("ERC")
decimals := felt.Felt{}
decimals.SetUint64(18)
totalSupply := felt.Felt{}
totalSupply.SetUint64(1000000000000000000)
receipt := felt.Felt{}
receipt.SetUint64(1)

calldata := felt.Felt{}
calldata.Add(&name, &symbol)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to figure out how to construct calldata of the universal Deploy contract


// 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, &calldata}, //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

}
Loading